NewTopicAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:2k
- package StudyBbs;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import org.apache.struts.action.Action;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.DynaActionForm;
- import javax.servlet.ServletContext;
- import javax.sql.DataSource;
- import java.sql.Connection;
- import org.apache.struts.action.ActionMessage;
- import org.apache.struts.action.ActionMessages;
- public final class NewTopicAction extends Action{
- public ActionForward execute(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws Exception {
-
- HttpSession session = request.getSession();
- ActionMessages errors = new ActionMessages();
-
- String username=(String)session.getAttribute(Constants.USERNAME_KEY);
-
- String PageForward;
- if (username==null) {
- errors.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("errors.userUnLogin"));
- if (!errors.isEmpty()) {
- saveErrors(request, errors);
- }
- PageForward="toWrong";
-
- }
- else if (username.equals("guest")){
- errors.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("errors.guestCantSpeak"));
- if (!errors.isEmpty()) {
- saveErrors(request, errors);
- }
- PageForward="toWrong";
-
- }else{
- PageForward="toNewTopic";
- saveToken(request); //避免重复提交
- }
- return (mapping.findForward(PageForward));
- }
- }