What is the role of ServletContext?

Source: Internet
Author: User

What is the role of ServletContext. getContect (java. lang. String uripath?

Returns the ServletContext object corresponding to the path specified in the same Server. This object can be used to deal with other contexts in the Server.

Uripath must start with "/" and indicate the root path relative to the entire Servlet document, rather than the root path of the current ServletContext ).

What is the difference between ServletContext. getRequestDispatcher (String url) and ServletRequest. getRequestDispatcher (String url? Why?

The URLs in ServletContext. getRequestDispatcher (String url) can only use absolute paths, while those in ServletRequest. getRequestDispatcher (String url) can use relative paths.

Because ServletRequest has the concept of relative paths, while ServletContext does not.

How do I transfer requests to an address in another Web App?

ServletContext. getRequestDispatcher (String url) and ServletRequest. getRequestDispatcher (String url) can only transfer requests to addresses in the same Web App.

To transfer requests to an address in another Web App, follow these steps:

1. Obtain the ServletConext object (currentServletContext. getContext (uripath) of another Web App )).

2. Call the ServletContext. getRequestDispatcher (String url) method.

  1. How to install Apache Servlet
  2. Optimize Servlet configuration for web. xml slimming
  3. How to configure Servlet in XML
  4. Solve the Problem of Servlet JSP page garbled
  5. Servlet and JSP security issues

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.