Jsp and servlet learning summary, jspservlet Summary

Source: Internet
Author: User

Jsp and servlet learning summary, jspservlet Summary
I. Differences between Jsp and servlet:

Jsp is a java code embedded in html and html is controlled by java code.

Servlet is completely composed of JAVA program code, used for process control and transaction processing

Jsp is better at page display and servlet is better at logical control.

The Servlet does not contain built-in objects. The embedded objects in Jsp must be obtained through the HttpServletRequest object, HttpServletResponse object, and HttpServlet object.

2. How to configure a servlet for running

1. servlet name, package class

<Servlet>

<Servlet-name> httpServletDemo (name obtained for servlet) </servlet-name>

<Servlet-class> com. lxitedu. HttpServletDemo (package name. class Name) </servlet-class>

</Servlet>

 

2. ing. Access address (url)

<Servlet-mapping>

<Servlet-name> httpServletDemo (same as the servlet name above) </servlet-name>

<Url-pattern>/myServlet (name of the file displayed in the address bar during runtime) </url-pattern>

</Servlet-mapping>

Iii. servlet jump Method

1). Use the action attribute of the form to set the page to jump to (this method can pass the form attribute value of this page to the next page ):

<Form action = "my. jsp" name = "lili" onsubmit = "return test ()">

<Input type = "submit" value = "submit">

Or (manually submit the form for the button type ):

<Input type = "button" value = "register" onclick = "test ()">

Javascript Functions:

Function test (){

// Manually set the jump page

Document. lili. action = "my1.jsp ";

Document. lili. submit ();

}

2). Use the page Jump method in javascript (the attribute values in form cannot be passed to the next page ):

Window. location. href = "my. jsp ";

Window. location. replace ("my. jsq"); // This method cannot be used to remove the page.

2. Comparison of Two Methods for server jump:

<Jsp: forward page = "xxx. jsp"/>: equivalent

Request. getRequestDispatcher ("xxx. jsp"). forward (request, response );

This server provides more efficient resource redirection. The Address Bar remains unchanged (the page before the jump). You can obtain the request attribute value.

Response. sendRedirect ("xxx. jsp "):

Redirect to any resource. Change the address bar to the current page. The request attribute value cannot be obtained.

 

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.