📄 newsaction.java
字号:
package com.org.struts.action;
import java.lang.reflect.InvocationTargetException;
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 com.org.common.PageInfo;
import com.org.hibernate.vo.News;
import com.org.spring.service.NewsService;
public class NewsAction extends BaseAction {
//public ActionForward validate(ActionMapping mapping, ActionForm form,
// HttpServletRequest request, HttpServletResponse response)
// throws Exception {
// String PageForward;
// String username=(String)((DynaValidatorForm) form).get("username");
// String password=(String)((DynaValidatorForm) form).get("password");
// if(super.getNewsService().validate("username")==true){
// PageForward="tonewsMain";
// }
// else {
// System.out.println("the "+username+" is null!!");
// PageForward="towrong";
// }
// return mapping.findForward(PageForward);
//}
public ActionForward getAllNews(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
News[] news = super.getNewsService().getAllNews();
request.setAttribute("allnews", news);
return mapping.findForward("tonewsMain");
}
public ActionForward getNew(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception, IllegalAccessException,
InvocationTargetException {
String id = String.valueOf(request.getParameter("id"));
News news = super.getNewsService().getNew(id);
request.setAttribute("news", news);
return mapping.findForward("tonewsDetail");
}
public ActionForward insertNew(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String id = (String) ((DynaValidatorForm) form).get("id");
String title = (String) ((DynaValidatorForm) form).get("title");
String content = (String) ((DynaValidatorForm) form).get("content");
String author = (String) ((DynaValidatorForm) form).get("author");
String time = (String) ((DynaValidatorForm) form).get("time");
String keyword = (String) ((DynaValidatorForm) form).get("keyword");
Integer type =(Integer) ((DynaValidatorForm) form).get("type");
super.getNewsService().insertNew(id,title,content,author,time,keyword,type);
return mapping.findForward("toAdminMain");
}
public ActionForward updateNew(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception, IllegalAccessException,
InvocationTargetException {
String id = String.valueOf(request.getParameter("id"));
super.getNewsService().updateNew(id);
return mapping.findForward("toNewsEdit");
}
public ActionForward delNew(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String id = String.valueOf(request.getParameter("id"));
super.getNewsService().delNew(id);
return mapping.findForward("toAdminMain");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -