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.