Question about the action path in Form, form Form action path

Source: Internet
Author: User

Question about the action path in Form, form Form action path
Today, I just got into touch with some questions about the Form action attributes and method attributes when using jsp and servlet for a simple login;

What I encountered was a problem when the Form was submitted to servelet for 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">

(2) the corresponding servlet class for processing user requests is HelloServlet. java;

(3) configure the web. xml file:
<Servlet-name> ③ servlet </servlet-name>
<Servlet-class>/HelloServlet </servlet-class>

<Servlet-name> ③ servlet </servlet-name>
<Url-pattern>/① welcome </url-pattern>

In login. jsp, it should be:

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

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

The HelloServlet. java url is http: // localhost: 8080/jsp/welcome.

Available values in HelloServlet

String name = "";
String pwd = "";
Name = req. getParameter ("username ");
Pwd = req. getParameter ("pwd ");

Note: web. in xml, ③ the two servlet-names must be consistent; In ①, url-pattern must be consistent with the action attribute value in form; ③ The method is the get method by default, however, this method exposes the value to the browser, so the post method is generally used to hide the value content;

Question about the form action path in java

Generally, you should add a namespace to the package in struts. xml to configure the action path,
Then, make the namespace value consistent with the jsp folder name.
When writing the form action path, you can directly write the relative path. For example
<Form method = "post" action = "add_Emp.action">
As you can see, _ in the request of the landlord action should use wildcards in the action of struts. xml.
<Action name = "add _ *" class = "slightly" method = "{1}"> This is the common configuration usage.
Hope the landlord can use it happily

How to obtain the file path of form file in action?

<Form action = "" method = "post">
<Input type = "file" name = "file1"/>
Request. getParameter ("file1 ");

<Form action = "" method = "post" enctype = "multipart/form-data">
<Input type = "file" name = "file1"/>
ServletInputStream sis = request. getInputStream ();
Read with sis, one row for analysis.

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: 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.