您好,欢迎访问一九零五行业门户网

Jquery+ajax+JAVA(servlet)实现下拉菜单异步取值_jquery

首先来看工程结构图:
项目所需要的包,如下所示:
jsp代码:
jsoncase 点击取值
记录信息:
java servlet代码:
package servlet;import java.io.ioexception;import java.io.printwriter;import javax.servlet.servletexception;import javax.servlet.http.httpservlet;import javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;import net.sf.json.jsonarray;public class valuegetcontroller extends httpservlet { private static final long serialversionuid = -1293610555518403602l; /** * constructor of the object. */ public valuegetcontroller() { super(); } /** * destruction of the servlet.
*/ public void destroy() { super.destroy(); // just puts destroy string in log // put your code here } /** * the doget method of the servlet.
* * this method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws servletexception if an error occurred * @throws ioexception if an error occurred */ public void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { dopost(request, response); } /** * the dopost method of the servlet.
* * this method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws servletexception if an error occurred * @throws ioexception if an error occurred */ public void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { request.setcharacterencoding(gbk); response.setcontenttype(text/html;charset=gbk); printwriter out = response.getwriter(); string action = request.getparameter(action); system.out.println(action+action); if (action.equals(getfirstfloorvalue)) { string[] str = getfirstfloorvalue(); jsonarray ja = jsonarray.fromobject(str); string json = ja.tostring(); out.print(json); system.out.println(json); out.flush(); out.close(); return; } out.flush(); out.close(); } private string[] getfirstfloorvalue() { string[] str = new string[4]; str[0] = test1; str[1] = test2; str[2] = test3; str[3] = test4; return str; } }
关于servlet的web.xml配置:
this is the description of my j2ee component this is the display name of my j2ee component valuegetcontroller servlet.valuegetcontroller valuegetcontroller /valuegetcontroller index.jsp
以上就是本文的全部内容,希望对大家的学习有所帮助。
其它类似信息

推荐信息