📄 newsaction.java
字号:
package news.action;
import news.db.*;
import news.form.*;
import java.sql.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.DispatchAction;
import java.util.*;
public class NewsAction extends DispatchAction{
public ActionForward add(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception
{
News n = (News)form;
String target = "tip";
String temp="新闻发布失败";
NewsDAO aa = new NewsDAO();
try{
if(aa.insert(n)==1)
temp="新闻发布成功";
request.setAttribute("tip",temp);
}catch(Exception e){e.printStackTrace();}
return mapping.findForward(target);
}
public ActionForward searchAll(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception
{
String target = "sas";
NewsDAO newsDAO = null;
ArrayList ar = new ArrayList();
try{
newsDAO = new NewsDAO();
ar=newsDAO.searchAll();
request.getSession().setAttribute("ar",ar);
}catch(Exception e){e.printStackTrace();}
return mapping.findForward(target);
}
public ActionForward delete(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception
{
String id = request.getParameter("id");
String target = "del";
NewsDAO userDAO = null;
try{
userDAO = new NewsDAO();
userDAO.delete(id);
}catch(Exception e){e.printStackTrace();}
return mapping.findForward(target);
}
public ActionForward edit(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception
{
String id = request.getParameter("id");
String target = "ss";
NewsDAO userDAO = null;
News u = null;
try{
userDAO = new NewsDAO();
u=userDAO.search(id);
request.getSession().setAttribute("news",u);
}catch(Exception e){e.printStackTrace();}
return mapping.findForward(target);
}
public ActionForward update(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception
{
News u = (News)form;
String target = "tip";
String temp="新闻更新失败";
NewsDAO userDAO = null;
try{
userDAO = new NewsDAO();
if(userDAO.update(u)==1)
temp="新闻更新成功";
request.setAttribute("tip",temp);
}catch(Exception e){e.printStackTrace();}
return mapping.findForward(target);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -