Various methods of JSP page jump and request

Source: Internet
Author: User

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "Utf-8"%><! DOCTYPE html >${pagecontext.request.contextpath}style= "Cursor:pointer; width:50px; height:50px "> </a> <!--here is a server-side request with a tag, and the parameters are passed behind the link? Connect-<a href= "${pagecontext.request.contextpath}/jsppage/requestpage.ht?name=merida" > style= "Cursor:pointer; width:50px; height:50px "> </a> Form Action= "${pagecontext.request.contextpath}/jsppage/requestpage.ht" >Name:<input type= "text" name= "name" > <input type= "Submit"value= "Submit" > </form> Action= "${pagecontext.request.contextpath}/jsppage/requestpage.ht" >Name:<input type= "text" name= "name" > <a href= "#"onclick= "document.getElementById (' subform ')." Submit (); return false "> style= "Cursor:pointer;" > </a> </form> Action= "${pagecontext.request.contextpath}/jsppage/requestpage.ht" >Name:<input type= "text" name= "name" > <!--here is the role of the a tag is grafted to the IMG tag, and the same can be achieved when the form is submitted--style= "Cursor:pointer;"onclick= "document.getElementById (' Subform1 ')." Submit (); return false "> </a> </form> Request Forwarding: Request.getrequestdispatcher (URL address). Forward (request, response) Here is the use of the requested forwarding to request the server-<%--<%Request.setattribute ("Name", "GIANT"); /*request.getrequestdispatcher ("${pagecontext.request.contextpath}/jsppage.ht"). Forward (request, response);*/%>--%> /*here is the use of forwarding to jump the page on the client*/Request.getrequestdispatcher ("/jsppage/requestpage.jsp"). Forward (request, response); %>--%> <%--in a JSP page, you can use the <jsp:forward> tag to forward requests--%> <%--<jsp:forward page= "/JSPPAGE/REQUESTP Age.jsp ">--%></body>
 PackageResponseservlet;Importjava.io.IOException;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse; Public classResponseservletextendsHttpServlet {@Overrideprotected voidService (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {//get the app name for the projectString path= "\ \" +Request.getservername (); if(! (Request.getparameter ("name") = =NULL) ) {String name=request.getparameter ("name"); Response.getwriter (). println ("The value obtained from the request parameter" +name); Response.sendredirect (Path+ "/jsppage/redirectpage.jsp"); }Else{String namestring= (String) request.getattribute ("name"); Response.getwriter (). println ("Get out of request scope" +namestring); Response.sendredirect (Path+ "/jsppage/redirectpage.jsp"); }    }}
<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns: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_2_5.xsd"ID= "webapp_id"version= "2.5">  <Display-name>Requestmethod</Display-name>  <welcome-file-list>    <Welcome-file>/jsppage/index.jsp</Welcome-file>  </welcome-file-list>  <servlet>  <Servlet-name>Pagerequest</Servlet-name>  <Servlet-class>Responseservlet.responseservlet</Servlet-class>  </servlet>  <servlet-mapping>  <Servlet-name>Pagerequest</Servlet-name>  <Url-pattern>*.ht</Url-pattern>  </servlet-mapping></Web-app>

Various methods of JSP page jump and request

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.