⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newsaction.java

📁 用户能添加 查看 新闻内容 并能够修改新闻内容~
💻 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 + -