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

📄 addadminservlet.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 addAdminServlet 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;				PrintWriter out=response.getWriter();         response.setContentType("text/html;charset=gb2312");        response.setHeader("Refresh","3;URL=/news/admin/adminManage.jsp");        boolean b=false;        try{					id=request.getParameter("id");					password=request.getParameter("password");				  					if( id!=null&&password!=null&&!password.equals("") ){						if(id!=null)id=new String(id.getBytes("ISO-8859-1"),"gb2312");				  	if(password!=null)password=new String(password.getBytes("ISO-8859-1"),"gb2312");						b=myNews.createAdmin(id,password);					}		//if							if(b){						out.println(new String("add success!!,3 second later return".getBytes("ISO-8859-1"),"gb2312"));												}					else{						out.println("<script>alert('对不起,您设定的管理员ID已经被别人占用了!或者输入错误');history.back();</Script>");						}				}//try				catch(Exception ex){					out.println("<script>alert('对不起,您设定的管理员ID已经被别人占用了!或者输入错误');history.back();</Script>");				}//catch()										}//    }

⌨️ 快捷键说明

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