Google http://www.googto.com/
1. Forms
Here, the action in the form cannot take "/", without/representing the relative path, with "/" for absolute path, must be written/project name/url.
<%@ 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 "> 2, Web. XML configuration
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance " xmlns=" Http://java.sun.com/xml/ns/javaee " xmlns:web=" http://java.sun.com/xml/ns/ Javaee/web-app_2_5.xsd " xsi:schemalocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/ Xml/ns/javaee/web-app_3_0.xsd " id=" webapp_id " version=" 3.0 "> <display-name> Pro-web02</display-name> <welcome-file-list> <welcome-file >login.jsp</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> < welcome-file>index.jsp</welcome-file> <welcome-file>default.html</ welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>loginServlet</servlet-name> <servlet-class> cn.com.login.web.logincontroller</servlet-class></servlet><servlet-mapping> <servlet-name>loginservlet</servlet-name> <url-pattern>/ Loginservlet</url-pattern></servlet-mapping></web-app>
There must be a/in the url-pattern here, or it will error java.lang.IllegalArgumentException:Invalid <url-pattern> in servlet mapping
3. Logincontroller rewrite Dopost and Doget code
Reference W3cschool in the servlet tutorial
Http://www.runoob.com/servlet/servlet-form-data.html
Public class logincontroller extends httpservlet{private static final long serialversionuid = 1l;public logincontroller () {super ();} Public void doget (httpservletrequest request, httpservletresponse response) throws servletexception , ioexception{// Setting the Response content type Response.setcontenttype ("Text/html;charset=utf-8"); System.out.println ("User name" + request.getparameter ("Usercode")); Printwriter out = response.getwriter (); string title = "Using get method to read form data"; string doctype = "<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\" >\n "Out.println (doctype + ")
Servlets develop simple Java Web projects