About the path of Servlet forwarding to JSP pages (mandatory), servletjsp

Source: Internet
Author: User

About the path of Servlet forwarding to JSP pages (mandatory), servletjsp

I. phenomena and concepts

1. Problem

When the Servlet is forwarded to the JSP page, the Servlet Path is displayed in the address bar of the browser, if the JSP page hyperlink is relative to the JSP page address and the Servlet and the JSP page are not in the same folder, the path is messy.

2. absolute path Concept

The path relative to the contextPath (Context of the current Web application.

Solution: use absolute paths instead of relative paths for hyperlinks. If/Represents the root directory of the site, add contextPath before it.

<a href="<%= request.getContextPath() %>/TestServlet" rel="external nofollow" >To B</a>

Ii. Summary of '/' in Java Web Development

1. root path of the current Web Application

'/' Indicates http: // localhost: 8080/contextPath/: address processed by Servlet

1) forwarding: request. getRequestDispatcher ("/path/B. jsp"). forword (request, response );

2) map Servlet access paths in the web. xml file

<servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/TestServlet</url-pattern></servlet-mapping>

3) '/' in various custom labels '/'.

2. root path of the Web site

'/' Indicates http: // localhost: 8080/: address processed by the browser

1) hyperlink: <a href = "/TestServlet" rel = "external nofollow"> To B </a>

2) action in the form Tag: <form action = "/B. jsp">

3) redirection: response. sendRedirect ("/B. jsp ");

The above discussion about the path of Servlet forwarding to the JSP page (mandatory) is all the content shared by the editor. I hope you can give us a reference and support for the house of friends.

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