Request. getrequesturi ()/jqueryweb/resources/request. jsp
Request. getrequesturl () http: // localhost: 8080/jqueryweb/resources/request. jsp
Request. getcontextpath ()/jqueryweb
Request. getservletpath ()/resources/request. jsp
Note: resources is the directory name under webcontext.
Jqueryweb is the project name
-----------------------------------------------------
<% = Request. getrequesturi () %> <br/>
<% = Request. getrequesturl () %> <br/>
<% = Request. getcontextpath () %> <br/>
<% = Request. getservletpath () %> <br/>
<% = Request. getpathinfo () %> <br/>
Result:
Test-struts.jsp
Http: // 127.0.0.1: 8080/test-struts.jsp
Test-struts.jsp
Null
Configuration:
<Action name = "test" class = "teststrutsaction" method = "test">
<Result>/test-struts.jsp </result>
</Action>
Assume that your web application is named "news". In the browser, enter the Request Path:
Http: // localhost: 8080/news/main/list. jsp
Then execute line-orientedCodeThe following result is printed:
1. system. Out. println (request. getcontextpath ());
Print result:/news
2. system. Out. println (request. getservletpath ());
Print result:/main/list. jsp
3. system. Out. println (request. getrequesturi ());
Print result:/news/main/list. jsp
4. system. Out. println (request. getrealpath ("/"));
Print the result: F: \ Tomcat 6.0 \ webapps \ news \ test