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

📄 checkuser.java~11~

📁 一个J2EE四层架构的实例
💻 JAVA~11~
字号:
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);      }      Collection col =ejbAccountsHome.findByType("张 瑾");      if(col.isEmpty())      {        log("No accounts were found!");      }      int j=10;      Iterator it = col.iterator();      while (it.hasNext())      {        ejbAccounts=(EjbAccounts) PortableRemoteObject.narrow(it.next(), EjbAccounts.class);        log("Account " + ejbAccounts.getPrimaryKey() +            "; balance is $" + ejbAccounts.getBal()+" "+ejbAccounts.getType());        // double x=ejbAccounts.deposit(100.0*j);        double x=ejbAccounts.deposit(100.0*j);        x=ejbAccounts.withdraw(5000.0);        out.println("当前账户现金为: "+x);       // ejbAccounts.remove();        j++;      }    }    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 + -