Browser-side with a bar
The address of the first browser http://localhost:8080/example/index.jsp
If written
<ahref="/SERVLET/TESTDBSVL"> Click to enter servlet</a>
with the bar, is the absolute path, from the http://localhost:8080/
Start recording, which means
Http://localhost:8080/servlet/TestDBSvl
Clicking on the link occurs when the client jumps, URL Change
So this is going to start with the app name.
<imgsrc="/images/back.png"alt= ""/>
I can't find them.
With no bars.
The address of the first browser http://localhost:8080/example/index.jsp
But if it's not with a bar,
<ahref="myjsp.jsp"> Click to enter a new page </a>
is the relative engineering name started looking for
Clicking on the link occurs when the client jumps, URL Change
<imgsrc="/images/back.png"alt= ""/>
can find
Http://localhost:8080/example/images/back.png
?
Server-side servletrequestdispatcher with a bar
???? Request.getrequestdispatcher ("/myjsp.jsp"). Forward (request,response);
Obviously, the URL hasn't changed.
?
Relative path without a bar
Request.getrequestdispatcher ("myjsp.jsp"). Forward (request,response);
Did not remove the servlet
Servlet jump to page can I find a picture?
Request.getrequestdispatcher ("/index.jsp"). Forward (request,response);
index.jsp
<imgsrc="Images/back.png"alt= ""/>
can find pictures
?
Http://localhost:8080/example/images/back.png
Redirect
browser in " http://localhost:8080/example//SERVLET/TESTDBSVL
With a bar.
Request.getrequestdispatcher ("/index.jsp"). Forward (Request,response);
can find the page http://localhost:8080/example/index.jsp
?
Response.sendredirect ("/myjsp.jsp");
http://localhost:8080/MyJsp.jsp the page could not be found!
Of course, the page cannot be found on the browser side.
http://localhost:8080/MyJsp.jsp
?
With no bars.
Response.sendredirect ("myjsp.jsp");
//http://localhost:8080/example/servlet/myjsp.jsp Page not found
???????? // There 's no way I can write it all.
Of course, the page can be found on the browser, because it is relative to
http://localhost:8080/example/index.jsp to say
Jsp:forward
<jsp:forwardpage="/myjsp.jsp"/>
Server jump, can find the page
?
Summary with the absolute address of the bar
Addressing method = offset + address
Offset
Client Jump http://localhost:8080
Server-side Jump Http://localhost:8080/example
This offset is not related to whether you're on the browser or the servlet.
?
Relative address without a bar
The way to address is to cross out the last \ Post, plus the relative new address you wrote.
So what happens if I write a two?
Browser Address http://localhost:8080/example/index.jsp
<%response.sendredirect ("example/myjsp.jsp"); %>
The addressing result is http://localhost:8080/example/example/MyJsp.jsp
so no matter how many you have, it's the last \ post of the previous address, plus the new address.
?
Note is not necessarily the address displayed on the address bar of the browser
Like what
Index.jsp into the servlet, the address bar is
Http://localhost:8080/example/servlet/TestDBSvl
Then through the dispatcher, back to the index.jsp
The address bar is still not servlet, click Relative path
<ahref="myjsp.jsp"> Click to enter a new page </a>
Can you find it?
I can do that!
http://localhost:8080/example/MyJsp.jsp
?
So what am I writing?
For development, a unified standard, the most important, or to want to go on for half a day,
Write a bar, you have to judge the server jump or browser jump
Write without a bar, relative path iffy
So, all with
It's all written, so you don't bother.
<base?href= "<%=basePath%>" >
Discard the <%=BASEPATH%>SERVLET/STOREDISHSVL before, but add this to the head of the page
<!--? base need to put inHeadin ?-->
<base?href= "<%=basePath%>" >
//?Here we can use the relative path directly(that:?relative toBaselabel)
<a?href= "jsp/login.jsp" >Login</a>
For servlet dispatcher writing a bar
For servlet redirect with no bar, no, it's all written.
JSP relative path and absolute path quest