Servlets develop simple Java Web projects

Source: Internet
Author: User

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

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.