日期:2014-05-18  浏览次数:20661 次

javaweb 根路径问题
我用html做页面,form表单地址栏写action="/xxAction.do"时候地址栏会变为
http://localhost:8080/xxAction.do.

我想要的是带上项目名的地址,应该怎么做?
就是要这种效果
http://localhost:8080/projectname/xxAction.do
javaweb 绝对路径?

------解决方案--------------------
<%=request.getContextPath()%>
或者
${pageContext.request.contextPath}

如果没有记错的话。。。
------解决方案--------------------
页面前面加上这个,
<%
 String path = request.getContextPath();
 System.out.println(path);
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>
地址这样写就好了
action="<%= basePath %>/xxAction.do"