呵呵
实现的方法也许有很多,但我现在用的是这样的,在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;
………………………………
实现的方法也许有很多,但我现在用的是这样的,在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;
………………………………
doPost(request,response);
防止jsp以get方式提交,而得不到处理。
在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!