在eclipse中先在tomcat的conf/server.xml中配置java项目路径,然后在jsp中使用路径的时候就使用类似于<a href="/emp.do?method=list">的路径,web.xml中配置<url-pattern>/emp.do</url-pattern>就可以了,但是现在我改在myeclipse中,因为文件可以部署在tomcat中,所以不用改动server.xml了,文件中路径使用<a href="emp.do?method=list">,因为前面加上了程序的目录文件,路径变成了“项目名/admin/emp.do”,web.xml中的<url-pattern>/emp.do</url-pattern>也不能改,一改就出错,不改又找不到文件,请教我该怎么办

解决方案 »

  1.   

    使用绝对路径时需将应用上下文加到请求路径中。如:<% String contextPath = request.getContextPath(); %> 
    <a href="<%=contextPath%>/emp.do?method=list">
    或者使用相对路径,即不以“/”开头的请求路径。如:<a href="emp.do?method=list">
      

  2.   

    <a href="emp.do?method=list">改为<a href="../emp.do?method=list">试试
      

  3.   

    我使用<a href="/Maneger/admin/emp.do?method=list">查询用户信息</a>,web.xml中使用<url-pattern>/admin/emp.do</url-pattern>,浏览器的地址也是对的http://localhost:8080/Maneger/admin/admin/emplist.jsp,但是却报404错误
      

  4.   

    http://localhost:8080/Maneger/admin/admin/emplist.jsp,你这个路径是不是多了个admin?
    还有,最好使用绝对路径,相对路径在项目迁移过程中很容易出问题