?? newsaction.java
字號(hào):
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="新聞發(fā)布失敗";
NewsDAO aa = new NewsDAO();
try{
if(aa.insert(n)==1)
temp="新聞發(fā)布成功";
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);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -