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

📄 adminmanageservlet.java

📁 NONO一族J2EE新闻系统 采用了目前流行的J2EE技术
💻 JAVA
字号:
/* * *  *  */package util;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import news.*;import javax.ejb.*;import javax.naming.*;import javax.rmi.PortableRemoteObject;import java.rmi.RemoteException;/** * This is a simple example of an HTTP Servlet.  It responds to the GET * method of the HTTP protocol.  */public class AdminManageServlet extends HttpServlet {			private News myNews = null;   public void init() throws ServletException {              try {         InitialContext ic = new InitialContext();         Object objref = ic.lookup("java:comp/env/ejb/TheNews");         NewsHome home = (NewsHome)PortableRemoteObject.narrow(objref,NewsHome.class);         myNews = home.create();		       } catch (RemoteException ex) {            System.out.println("Couldn't create news bean."+ ex.getMessage());      } catch (CreateException ex) {            System.out.println("Couldn't create news bean."+ ex.getMessage());      } catch (NamingException ex) {            System.out.println("Unable to lookup home: "+ "TheNews "+ ex.getMessage());      } catch(Exception ee){}   }   public void destroy() {         myNews = null;   }         public void doPost (HttpServletRequest request,HttpServletResponse response)        throws ServletException, IOException {        util.CheckLogin.isLogin(request,response);	//验证合法性        	        String id=null;        String password=null;        String Submit=null;				PrintWriter out=response.getWriter();         response.setContentType("text/html;charset=gb2312");        response.setHeader("Refresh","3;URL=/news/admin/adminManage.jsp");				Submit=request.getParameter("Submit");				if(Submit.equals("delete")){					try{						id=request.getParameter("id");						if(id!=null)id=new String(id.getBytes("ISO-8859-1"),"gb2312");						myNews.removeAdmin(id);						out.println("delete success!!,3 second later return");					}					catch(Exception ex){						out.println("<script>alert('failed 错误');history.back();</Script>");      		}//catch				}//if				else if (Submit.equals("modify")){					try{							id=request.getParameter("id");							if(id!=null)id=new String(id.getBytes("ISO-8859-1"),"gb2312");							password=request.getParameter("password");							if(password==null||password.equals("")||id==null||id.equals("")){								throw new Exception();							}//if								myNews.updateAdmin(id,password);								out.println("modify success!!,3 second later return");												}//try					catch(Exception ex){							out.println("<script>alert('failed 错误');history.back();</Script>");      		}//catch				}//else if				        						}//doPost				public void doGet (HttpServletRequest request,HttpServletResponse response)        throws ServletException, IOException {        	doPost (request,response);    }//doGet    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -