超链接无法访问servlet的问题(错误代码404)
超链接访问servlet <h3><A href="/UsercheckServlet?tager="+admin>管理员入口</A></h3>
可是当我点击超链接时,却找不到servlet(错误代码404)
web.xml配置如下:
<servlet>
<servlet-name>dis</servlet-name>
<servlet-class>com.wl.control.UsercheckServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dis</servlet-name>
<url-pattern>/UsercheckServlet</url-pattern>
</servlet-mapping>
我的网站目录是这样的 F:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\stuCor (stuCor是我的网站)
以下是servlet(很简单的,就几行代码,麻烦各位高手看完)
package com.wl.control;
import
java.io.IOException;
import java.io.PrintWriter;
import
javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UsercheckServlet extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws
ServletException if an error occurred
* @throws
IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String u=request.getParameter("tager");
try {if (u.equals("a")){
request.getRequestDispatcher("1.jsp").forward(request, response);
}
else if (u.equals("b")){
request.getRequestDispatcher("2.jsp").forward(request, response);
}
}catch (Exception ex){
ex.printStackTrace();
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
请各位高手指点 我哪出错了 谢谢啦
------解决方案--------------------
<h3><A href="<%=request.getContextPath()%>/UsercheckServlet?tager="+admin>管理员入口</A></h3>试试
不好用的话,把Tomcat换个路径之间的没有空格的地方