The action path problem in form form, form form action path "JSP--->servlet Road" this and the previous "JSP--->servlet" article about

Source: Internet
Author: User

Action path problem in form form, form form action path

Heat5 reviews

Www.BkJia.Com netizens share: 2014-08-14 08:08:01 views 44,525 times

Action path problem in form form, form form action path
Just touch the web today, when using JSP and servlet to do a simple landing in the form form the Action property and the method attribute some problems;


I encountered an issue with the form form submission to Servelet processing:
(1) <form name= "Login" action= "①? "Method=" ②? ">

Form content

Username:<input type = "text" name = "username" > <br>
Password:<input type = "password" name = "pwd" > <br>
<input type = "Submit" >
</form>

(2) The corresponding servlet class for processing user requests is Helloservlet.java;


(3) Configure the Web. xml file:
<servlet>
<servlet-name>③servlet</servlet-name>
<servlet-class>/HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>③servlet</servlet-name>
<url-pattern>/①welcome</url-pattern>
</servlet-mapping>

Then in the login.jsp it should be:

<form action= "①welcome" method= "②? ">

In this case, the login.jsp URL is http://localhost:8080/jsp/login.jsp

And the URL of Helloservlet.java is Http://localhost:8080/jsp/welcome

Values can be taken in HelloServlet

String name = "";
String pwd = "";
Name = Req.getparameter ("username");
PWD = Req.getparameter ("pwd");

Note: The ③ corresponds to the two servlet-name in Web. XML, and the Url-pattern in ① is consistent with the Action property value in the form form; The ③method method defaults to the Get method, but this method exposes the value to the browser. So the general use of the Post method, hidden value content;


For the form form action path problem in Java

Path configuration for general action you should add a namespace to the package in Struts.xml.
Then let the namespace value match the name of the JSP folder.
So when you write the action path of the form, you can write the relative path directly. For example
<form method= "POST" action= "Add_emp.action" >
and see the landlord action request has _ should be in the Struts.xml action with a wildcard bar
<action name= "add_*" class= "slightly" method= "{1}" > This is the usual usage of the configuration
Hope the landlord can use the happy

How to get the file path of form form file type in action

<form action= "" method= "POST" >
<input type= "File" name= "File1"/>
</form>
Request.getparameter ("File1");

<form action= "" method= "Post" enctype= "Multipart/form-data" >
<input type= "File" name= "File1"/>
</form>
ServletInputStream sis = Request.getinputstream ();
With SIS read, one line of analysis.

The action path problem in form form, form form action path "JSP--->servlet Road" this and the previous "JSP--->servlet" article about

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.