比如这个页面
http://localhost:8080/questionvsanswer/question/2里面的连接 <a href="<s:url action='register'/>">注册</a>这个连接产生的是 源码是:<a href="/questionvsanswer/question/register">注册</a>
如何生成/questionvsanswer/register只对工程的相对链接,而不是对/questionvsanswer/question的相对链接
http://localhost:8080/questionvsanswer/question/2里面的连接 <a href="<s:url action='register'/>">注册</a>这个连接产生的是 源码是:<a href="/questionvsanswer/question/register">注册</a>
如何生成/questionvsanswer/register只对工程的相对链接,而不是对/questionvsanswer/question的相对链接
contextPath = questionvsanswer
所以一般用绝对路径比较好
如果一定用相对路径,那就这样写: <a href="<s:url action='../register'/>">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head><base href="<%=basePath%>" /></head>