Environment: Eclipse Mars
1. New Dynamic Web
2, new JSP page, code:
<% @page import= "com.kuaiya.query.process.QueryProcess"%>
<%@ page language= "java" contenttype= "text/" html Charset=utf-8 "
pageencoding=" UTF-8 "%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
3. New Servlet
Package com.kuaiya.query.process;
Import java.io.IOException;
Import javax.servlet.ServletException;
Import Javax.servlet.annotation.WebServlet;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse; /** * Servlet Implementation class Queryprocess/@WebServlet ("/queryprocess") public class Queryprocess extends Httpse
Rvlet {private static final long serialversionuid = 1L;
/** * @see httpservlet#httpservlet () * * * Public queryprocess () {super (); TODO auto-generated Constructor stub}/** * @see httpservlet#doget (httpservletrequest request, HTTPSERVLETRESP Onse response) */public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexceptio
N, IOException {//TODO auto-generated Method stub doPost (request, response); /** * @see Httpservlet#dopost (httpservletrequest request, httpservletresponse response) * *
public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {//
TODO auto-generated Method Stub String query = Request.getparameter ("SQL");
String btn = Request.getparameter ("Query");
if (Btn!=null && btn.equals ("query")) {Query.lstSubmit.add (query);
try {query.process ();
catch (Interruptedexception e) {//TODO auto-generated catch block E.printstacktrace ();
}
}
}
}
Note: In JSP you need to add
<form action= "Queryprocess" >
</form>
Otherwise, the running interface button clicks the Dopost function in the servlet cannot be triggered.