📄 checkuser.java~5~
字号:
package sqlaccounts;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import javax.ejb.*;import javax.rmi.*;import javax.naming.*;import java.sql.*;import java.lang.String;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class CheckUser extends HttpServlet implements SingleThreadModel{ static final private String CONTENT_TYPE = "text/html; charset=GBK"; //Initialize global variables public void init() throws ServletException { } //Process the HTTP Get request public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>CheckUser</title></head>"); out.println("<body>"); out.println("<p>The servlet has received a GET. This is the reply.</p>"); out.println("</body></html>"); } //Process the HTTP Post request public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /*response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>CheckUser</title></head>"); out.println("<body>"); out.println("<p>The servlet has received a POST. This is the reply.</p>"); out.println("</body></html>");*/ try { response.setContentType("text/html"); PrintWriter out=response.getWriter(); //用于系统向客户端输出信息的变量 String userID=request.getParameter("USER_ID"); //用于记录客户ID值 String userPassword=request.getParameter("PASSWORD"); //用于记录客户密码 String userLoginManager=request.getParameter("ManageOrNot"); //用于记录客户权限状态(是否为管理员) //WebLogic服务器用户密码 String redirectURL; //记录重定向地址 //用上面启动的参数获得初始的JNDI context Context ctx = getInitialContext(); //通过JNDI查找需要的本地对象 Object ref = ctx.lookup("EjbAccountsRemote"); //cast to Home interface private EjbAccountsHome ejbAccountsHome = null; EjbAccounts ejbAccounts = null; EjbAccountsHome ejbAccountsHome = (EjbAccountsHome) PortableRemoteObject.narrow(ref, EjbAccountsHome.class); //使用制作生成库生成EJB对象 Identify userinfo=home.create(); //取得当前用户的真实姓名 String name=userinfo.getName(userID,userPassword); //取得当前用户的使用权限 int icheckLevel=userinfo.getLevel(userID,userPassword); //通过对使用权限和客户所选的权限状态判断,重定向页面 if(userLoginManager!=null && icheckLevel==1) { redirectURL = response.encodeURL("http://192.168.0.87:8090/backProc.jsp?username="+name+"&userid="+userID+"&userlevel=1"); response.sendRedirect(redirectURL); } else if (userLoginManager==null && icheckLevel==0) { redirectURL = response.encodeURL("http://192.168.0.87:8090/backProc.jsp?username="+name+"&userid="+userID+"&userlevel=0"); response.sendRedirect(redirectURL); } else if (userLoginManager==null && icheckLevel==1) { redirectURL = response.encodeURL("http://192.168.0.87:8090/backProc.jsp?username="+name+"&userid="+userID+"&userlevel=0"); response.sendRedirect(redirectURL); } else { redirectURL = response.encodeURL("http://192.168.0.87:8090/relog.html"); response.sendRedirect(redirectURL); } } catch(Exception e) { System.out.println(e); } } //Process the HTTP Put request public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } //Process the HTTP Delete request public void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } //Clean up resources public void destroy() { } private Context getInitialContext() throws Exception { String url = "t3://3as:7001"; String user = null; String password = null; Properties properties = null; try { properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, url); if (user != null) { properties.put(Context.SECURITY_PRINCIPAL, user); properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password); } return new InitialContext(properties); } catch(Exception e) { log("Unable to connect to WebLogic server at " + url); log("Please make sure that the server is running."); throw e; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -