路径
前言:编写代码时 首先明白当前文档的路径
服务器端的地址:
绝对路径:
即相对于http://localhost:8080/MyApp/的。
其用到的地方有:
forwarder:servlet中的request.getRequestDispatcher(address);这个address是在服务器端解析的,所以,你要forwarder到login.jsp应该这么写:request.getRequestDispatcher("/pages/login.jsp")这个/相对于当前的web应用webapp,其绝对地址就是:http://localhost:8080/MyApp/pages/login.jsp。
sendRedirect:在jsp中<%response.sendRedirect("/pages/login.jsp");%>
相对路径:
即相对于当前工作路径同级的路径:
http://localhost:8080/path/ssl/cert/test
Forward:a.jsp
http://localhost:8080/path/ssl/cert/a.jsp
客户端的地址:
绝对路径:
所有的html中的绝对地址都是相对于http://localhost:8080/的,而不是http://localhost:8080/MyApp/的。
Html中的form表单的action属性的地址应该是相对于http://localhost:8080/的,所以,如果提交到login.jsp为:action="/MyApp/pages/login.jsp";提交到servlet为 action="/MyApp/login.do"
Javascript也是在客户端解析的,所以其相对路径和form表单一样。
相对路径:
那要看当前页面(地址栏)与所要跳转页面的位置关系
同在一个目录的window.location = './b.html' 或者 window.location='b.html'
上一级目录的 window.location = '../b.html' 可以用
跳到不同域的 window.location = 'http://www.baidu.com/'
设置base:
<base href="http://www.w3school.com.cn/i/" />
href 属性规定页面中所有相对链接的基准 URL。不包括:location!
实例:
可以设置默认访问页面/servlet
SSL/admin/Login.jsp
例如:login.jsp
https://192.168.1.171:9443/SSL/admin/Login.jsp
Login.jsp ------- /SSL/cert/RootServlet(RootServlet.java)
<a href="javascript:LinkTo('/SSL/cert/RootServlet')" style='font-size:12px'>安装可信证书链</a>
function LinkTo(html)
{
var url = "";
var path = document.location.pathname;
var host = document.location.host; //https://192.168.1.171:9443 //document.location.host // 域名+端口号
var index = 0;
var address = "";
index = host.indexOf(":");
if(index > 1)
{
address = host.substring(0, index);
}
else
{
address = host;
}
url = "http://" + address + ":<%out.print(GlobalConstants.PORT_SSLBOX_HTTP_SYS);%>";
url = url + html;
document.location = url;//https://192.168.1.171:9443/ SSL/cert/RootServlet
}
RequestDispatcher dispatcher = request.getRequestDispatcher(jspFile); dispatcher.forward(request, response);
document.location="CARootNonScriptServlet"
<servlet-mapping>
<servlet-name>CARootNonScriptServlet</servlet-name>
<url-pattern>/cert/CARootNonScriptServlet</url-pattern>
</servlet-mapping>
RequestDispatcher dispatcher = request.getRequestDispatcher(jspFile); dispatcher.forward(request, response);
<form name="CertsForm" action="CertsLinkDownloadServlet" method="post">
<servlet-mapping>
<servlet-name>CARootNonScriptServlet</servlet-name>
<url-pattern>/cert/CARootNonScriptServlet</url-pattern>
</servlet-mapping>
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String value = request.getParameter("Certs");
System.out.println(value);
byte buffer[] = value.getBytes();
response.setContentType("application/x-pkcs7-certificates");
response.setHeader("Content-disposition", "attachment; filename=certificates.p7b");
response.setContentLength(buffer.length);
response.getOutputStream().write(buffer);
}
posted on 2013-11-15 14:40 TrustNature 阅读(63) 评论(0) 收藏 举报
浙公网安备 33010602011771号