stanly00
stanly00
2016-05-11 15:31
采纳率: 100%
浏览 2.3k
已采纳

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 09:36
    已采纳

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

    点赞 评论
  • devmiao
    devmiao 2016-05-11 15:47
    点赞 评论
  • GHSYue
    GHSYue 2016-05-12 03:32

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

    点赞 评论

相关推荐