首页>代码>SSH极简新闻发布管理系统>/NRS/src/org/yeeku/action/AddNewsAction.java
package org.yeeku.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;
import org.yeeku.action.base.BaseAction;
import org.yeeku.model.Category;
import org.yeeku.model.News;
import org.yeeku.model.User;
import org.yeeku.webapp.util.AppConstants;

public class AddNewsAction extends BaseAction
{
    //必须重写该核心方法,该方法actionForm将表单的请求参数封装成值对象
    public ActionForward execute(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response)throws Exception
    {
        DynaValidatorForm loginForm = (DynaValidatorForm)form;
        String title = (String)loginForm.get("title");
        String content = (String)loginForm.get("content");
        String cateId = (String)loginForm.get("categoryId");

        try
        {
            Category category = mgr.getCategory(cateId);
            String username = (String)request.getSession(true).getAttribute(
                    AppConstants.LOGIN_USER);
            User poster = mgr.getUser(username);
            News news = new News();
            news.setCategory(category);
            news.setPoster(poster);
            news.setTitle(title);
            news.setContent(content);
            news.setPostDate(new Date());
            news.setLastModifyDate(new Date());
            mgr.saveNews(news);
        }
        catch (Exception e)
        {
            request.setAttribute("categoryId" , cateId);
            return mapping.findForward("failure");
        }
        request.setAttribute("categoryId" , cateId);
        return mapping.findForward("success");
    }
}
最近下载更多
最代码官方  LV167 2023年8月27日
最近浏览更多
wwfl02  LV3 2023年10月10日
漫步的海星  LV4 2023年9月21日
186092  LV4 2023年9月19日
你爹正在加载中  LV4 2023年9月11日
3263394665  LV9 2023年9月9日
fesfefe  LV13 2023年9月6日
最代码官方  LV167 2023年8月27日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友