2 stanly00 stanly00 于 2016.05.11 23:31 提问

java web 项目开发遇到HTTP405错误问题,求高手指点

这是UserServlet
public class UserServlet extends HttpServlet{

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=GBK");
    request.setCharacterEncoding("GBK");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>UserServlet</title></head>");
    out.println("<body bgcolor=\"#ffffff\">");
    out.println("<h3>我的聊天器,进入聊天系统...");
    ServletContext context = getServletContext();
    //判断用户列表存在
    if(context.getAttribute("userlist")==null){
        Vector aduser = new Vector();
        context.setAttribute("userlist",aduser);
    }
    //判断信息列表存在
    if(context.getAttribute("messagelist")==null){
        Vector message = new Vector();
        context.setAttribute("messagelist",message);
    }
    out.println("<form method='post' action='/SessionTrackingDemo/servlet/MainServlet'>");
    out.println("昵称<input type='text' name='uname'/>");
    out.println("<input type=submit value='登录'/>");
    out.println("</form>");
    out.println("</body>");
    out.println("</html>");
    out.flush();
    out.close();
}

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    doGet(request, response);
}

}

这是MainServlet
public class MainServlet extends HttpServlet {
private static final String CONTEXT_TYPE = "text/html;charset=GBK";
//添加用户请求分派
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTEXT_TYPE);
request.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
out.println("");
out.println("

MainServlet");
out.println("");
out.println("

进入聊天系统...");
ServletContext context = getServletContext();
Vector vc = (Vector)context.getAttribute("userlist");
String username = request.getParameter("uname");
vc.add(username);
RequestDispatcher view = request.getRequestDispatcher("/servlet/MessageServlet?uname="+username);
view.forward(request, response);
out.println("");
out.println("");
out.flush();
out.close();
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

}


从UserServlet跳转到MainServlet时出现HTTP405错误,求高手指点迷津
图片说明
图片说明
用的是weblogic服务器

3个回答

stanly00
stanly00   2016.05.12 17:36
已采纳

谢谢,找到错误了,是路径出错这种低级错误

devmiao
devmiao   Ds   Rxr 2016.05.11 23:47
GHSYue
GHSYue   2016.05.12 11:32

405错误指的是不允许此方法请求所标识的资源、不允许使用请求行中所指定的方法。试试post改为get

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!