addadminservlet.java

来自「J2EE技术开发的新闻发布系统。包括:分类管理、新闻管理、用户管理等基本功能.采」· Java 代码 · 共 84 行

JAVA
84
字号
/* * *  *  */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 + =
减小字号Ctrl + -
显示快捷键?