?? checkuser.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 + -