这是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("<html>"); out.println("<head><title>MainServlet</title></head>"); out.println("<body bgcolor="#ffffff">"); out.println("<h3>进入聊天系统..."); 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("</body>"); out.println("</html>"); out.flush(); out.close(); } @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
用的是weblogic服务器
从UserServlet跳转到MainServlet出现HTTP405错误,求高手指点.
解决方案
10
MainServlet中又跳到了MessageServlet,MessageServlet是怎么写的?
全部servlet的配置又是怎么定义的,都贴出来看看。
全部servlet的配置又是怎么定义的,都贴出来看看。
10
题主,你用的是doGet和doPost方法,你加一个service方法,把逻辑写在service方法里面就O了
20
MessageServlet 没有doPost()?