NewTopicAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. package StudyBbs;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import javax.servlet.http.HttpSession;
  5. import org.apache.struts.action.Action;
  6. import org.apache.struts.action.ActionForm;
  7. import org.apache.struts.action.ActionForward;
  8. import org.apache.struts.action.ActionMapping;
  9. import org.apache.struts.action.DynaActionForm;
  10. import javax.servlet.ServletContext;
  11. import javax.sql.DataSource;
  12. import java.sql.Connection;
  13. import org.apache.struts.action.ActionMessage;
  14. import org.apache.struts.action.ActionMessages;
  15. public final class NewTopicAction extends Action{  
  16. public ActionForward execute(
  17. ActionMapping mapping,
  18. ActionForm form,
  19. HttpServletRequest request,  
  20. HttpServletResponse response) throws Exception {
  21.         HttpSession session = request.getSession();
  22. ActionMessages errors = new ActionMessages();
  23.         
  24.         String username=(String)session.getAttribute(Constants.USERNAME_KEY);
  25.         
  26.         String PageForward;
  27.         if (username==null) {
  28.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  29.                            new ActionMessage("errors.userUnLogin"));
  30. if (!errors.isEmpty()) {
  31. saveErrors(request, errors);
  32.   PageForward="toWrong";  
  33.         
  34.         } 
  35.         else if (username.equals("guest")){
  36.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  37.                            new ActionMessage("errors.guestCantSpeak"));
  38. if (!errors.isEmpty()) {
  39. saveErrors(request, errors);
  40.   PageForward="toWrong";  
  41.         
  42.         }else{
  43.       PageForward="toNewTopic";
  44.   saveToken(request);  //避免重复提交
  45.         }
  46.        return (mapping.findForward(PageForward));
  47. }
  48. }