呵呵
实现的方法也许有很多,但我现在用的是这样的,在serlvet中增加一个方法,如下:
  protected void dispatch(HttpServletRequest request,
                          HttpServletResponse response, String page) throws
      CustomException {
    try {
    
      HttpSession s = request.getSession();
      ServletContext context = s.getServletContext();
      RequestDispatcher dispatcher = context.getRequestDispatcher(page); 
      dispatcher.forward(request, response);
    }
    catch (ServletException e1) {
      throw new CustomException(CustomException.DISPATCH_PAGE_FAILURE,
                                e1.getMessage());
    }
    catch (IOException e2) {
      throw new CustomException(CustomException.DISPATCH_PAGE_FAILURE,
                                e2.getMessage());
    }
  }
调用的时候,把request,response,和你要定向的地址page作为参数,象这样:
this.dispatch(request,response,"/jsp/test.jsp");
---------------------------------------------------
在dopost方法中,加入switch语句
switch (actionType) {
        //显示所有记录
        case Constant.ACT_DISPALY_ALL://这个就是你从页面传递过来的参数
          this.dispatch(request,response,"/jsp/displayAll.jsp");
          break;
          //显示课程详细信息
        case Constant.ACT_DISPLAY_DETAILS:
          action.dispatch(request, response,"/jsp/displayDetails.jsp");
          break;
  ………………………………

解决方案 »

  1.   

    在doGet方法中要加入
    doPost(request,response);
     防止jsp以get方式提交,而得不到处理。
      

  2.   

    如:
    在jsp一个文件中加入<input type="hidden" name="what" value="insert">
    在另一个文件中加入<input type="hidden" name="what" value="update">
    然后在servlet中加入
    if(request.getParameter("what").equals("insert"))
    { response.sendRedirect(a.jsp)}
    else if(request.getParameter("what").equals("update"))
    {response.sendRedirect(a.jsp)}就OK!
      

  3.   

    既然想这么做,为什么不用struts架构呢?
      

  4.   

    对啊,楼上的说的不错,用struts的actionmapping来控制页面的跳转哦
      

  5.   

    而且,有时候在servlet中经过各种处理以后,可能要把一些对象作为request的属性重新传递给jsp页面,用sendRedirect也是不好用的。