gpt4 book ai didi

java - 在 Struts 2 中使用 Ajax 和 Oracle 数据库自动完成文本框

转载 作者:太空宇宙 更新时间:2023-11-04 13:38:12 25 4
gpt4 key购买 nike

我正在尝试使用来自 Oracle 数据库中的作业表的值填充文本框,但我无法这样做,并且无法理解我在哪里犯了错误。下面是我的代码。

Jobs.java:

package action;

public class Jobs {
private String title;

public Jobs(String title) {
this.title = title;
}



public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}





AjaxAction.java:

package action;

import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import oracle.jdbc.rowset.OracleCachedRowSet;

public class AjaxAction extends ActionSupport{
//ArrayList<Jobs> jobs=new ArrayList<Jobs>();
ArrayList<String> jobs=new ArrayList<String>();

public ArrayList<String> getJobs() {
return jobs;
}

public void setJobs(ArrayList<String> jobs) {
this.jobs = jobs;
}


private String country;

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public String execute() throws Exception
{
OracleCachedRowSet crs=new OracleCachedRowSet();
crs.setUrl("jdbc:oracle:thin:@localhost:1521:XE");

crs.setUsername("**");
crs.setPassword("***");
crs.setCommand("select job_title from jobs");

crs.execute();
while(crs.next())
{
jobs.add(crs.getString("job_title"));

}
System.out.println(jobs);
return "success";
}



}

AjaxDemo.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="jq" uri="/struts-jquery-tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ajax Page</title>
<s:head/>
</head>
<body>
JOB TITLE <jq:autocompleter size="1" list="jobs" name="country">

</jq:autocompleter>

</body>
</html>

最佳答案

<%@taglib prefix="sj" uri="/struts-jquery-tags"%>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ajax Page</title>
<sj:head/>
</head>

sj:head 标签加载 jquery 库。

关于java - 在 Struts 2 中使用 Ajax 和 Oracle 数据库自动完成文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31494368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com