In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "Servlet and JSP path sample analysis," the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "Servlet and JSP path sample analysis" this article bar.
Premise: Suppose your Http address is http://192.168.0.1/webapp/, then your web app URL is http://192.168.0.1/webapp/
Directory structure of web applications:
◆webapp/
◆web-inf/
◆classes/
◆lib/
web.xml
handleservlet /handleservlet This mapping is relative to the current web application
◆user/
a.JSP
b.JSP
◆images/
◆css/
◆js/
All relative paths start with a "/." For example: /image/a. gif,/user/main.JSP, you know that the relative path in html is like this:
There is an html file: a.html, which has, where the href attribute indicates the path to the referenced css file. one.css: indicates that one.css and a.hmtl are in the same directory user/one.css: indicates that one.css is in the subdirectory user of a.html.…/ one.css: indicates that one.css is located in the directory one level above a.hmtl,…/…/one.css: indicates that one.css is located in the directory one level above a.hmtl.
We call this relative path html relative path
1. Server address
The server-side relative address refers to the address relative to your web application, which is resolved on the server side (unlike html and javascript relative addresses, which are resolved by client browsers). This means that the relative address in Servlet and JSP should be relative to your web application, i.e., relative to http://192.168.0.1/webapp/.
It is used where:
forwarder: request.getRequestDispatcher(address) in Servlet; This address is resolved on the server side, so you have to forward to a.JSP should be written like this: request.getRequestDispatcher("/user/a.JSP") This/relative to the current web application webapp, its absolute address is: 192.168.0.1/webapp/user/a.JSP.
sendRedirect: in JSP
2. Address of client
All html relative addresses are relative to http://192.168.0.1/, not http://192.168.0.1/webapp/.
The address of the action attribute of the form form in Html should be relative to http://192.168.0.1/, so if submitted to a.JSP: action="/webapp/user/a.JSP"; submitted to Servlet: action="/webapp/handleServlet"
Javascript is also parsed on the client side, so its relative path is the same as the form form.
3, site root directory and css path problem
We call relative paths like this/webapp/…Is a relative path to the site root directory.
When css is introduced in JSP, if its relative path is relative to that of the current JSP file, and in one and this JSP
Path is not the same Servlet forwarder this JSP, you will find that this CSS style does not work at all. This is because the css path when forwarded in a Servlet is the relative path to the Servlet rather than the JSP path. So you can't use paths in JSP at this time: or html-relative paths like href="one.css" and.../.../one.css are relative paths to files referencing this css. When forwarding in Servlet, it is relative to the relative path of this Servlet, because Servlet and JSP paths are different, so such references must be wrong.
So at this time, to use the site root directory, that is, relative to http://192.168.0.1/directory, with "/" at the beginning.
So the error above should be corrected to href="/webapp/one.css" relative to the root directory of a similar site. This Servlet forwarding and JSP are relative to the site root directory of the relative path, you can correctly use the defined css style.
Above is "Servlet and JSP path sample analysis" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.