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

📄 checkuser.java~6~

📁 一个四层结构的j2ee项目实例。对于初学者相当合适。欢迎下载使用。
💻 JAVA~6~
字号:
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";  String login; double amount; int namount; String samount; String Type;  //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();                                  //用于系统向客户端输出信息的变量               login=request.getParameter("Id");               samount=request.getParameter("Amount");               amount=Double.parseDouble(samount);               out.println(amount);               Type=request.getParameter("type");           //用于记录客户权限状态(是否为管理员)               //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对象              for(int i=0 ;i<30;i++)              {               ejbAccounts= ejbAccountsHome.create("11"+i*100,"zhangjin",100.0);              }               //取得当前用户的真实姓名                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 + -