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

问题描述 投票:0回答:1

我试图用来自 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>
java ajax jsp struts2 struts2-jquery
1个回答
0
投票
<%@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库。

© www.soinside.com 2019 - 2024. All rights reserved.