Java Dynamic web--jsp page invoke servlet (doPost) __.net

Source: Internet
Author: User
Tags stub

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.