jsp 中的路径问题

在jsp中<a href="/user/userAdd">添加用户</a>
如果点击这个链接,则会跳转到http://localhost:8080/user/userAdd这个地址

这是因为/user/userAdd中"/"代表tomcat web 应用程序的根路径即:http://localhost:8080,故会出现上述情况

解决方法:
<% String context = request.getContextPath(); %>   获取当前web应用程序的contextpath,然后加在前面,如下所示
<a href="<%=context %>/user/userAdd">添加用户</a>
posted @ 2012-06-14 21:30  feiling  阅读(160)  评论(0编辑  收藏  举报