requesthandler.java
来自「此程序都是企业级 的数据库开发程序 全面揭示了JAVA对数据库的操作」· Java 代码 · 共 59 行
JAVA
59 行
package mvc;import java.io.*;import java.util.*;/* * The two classes imported can be found as part of the J2EE v1.2.2 distribution available * from Sun's web site. These classes are part of the J2EE.jar that comes with the * distribution. If you have not downloaded this Jar you can also find the * classes in JBoss/Tomcat distributions. For the bundled JBoss/Tomcat distribution * these jars were located in: * javax.servlet.http.HttpServletRequest -%JBOSS DIRECTORY%/tomcat/lib/servlet.jar * javax.naming.InitialContext - %JBOSS DIRECTORY%/jboss/lib/ext/ejb.jar */import javax.servlet.http.HttpServletRequest;import javax.naming.InitialContext;/* * The org.w3c.dom.Document class is located in the Xalan jar. */import org.w3c.dom.Document;import mvc.templates.*;public class RequestHandler { /* * The process method is used to process a user request sent by the end-user. * It reads the request and action variables from the HttpServletRequest * parameter passed in. The request parameter returned from the HttpServletRequest * object is used to instantiate our EJB. The action parameter is used to define * whether the retrieve or post method of the instantiated bean is called. */ public Document process(HttpServletRequest _request) throws Exception { /* Step 1 - Retrieving the class parameters from the HttpServletRequest object */ String requestValue = _request.getParameter("Request"); String actionValue = _request.getParameter("Action"); /* Step 2 - Looking up and retrieving the desired EJB from JBoss */ InitialContext ctx = new InitialContext(); MVCHome home = (MVCHome) ctx.lookup(requestValue); MVCObject mvcComponent = home.create(); /* Step 3 - Deciding where to invoke the Retrieve or Post Method on the Bean */ if (actionValue.equals("Retrieve")) { return mvcComponent.retrieve(_request); } if (actionValue.equals("Post")) { System.out.println("I am in the post"); return mvcComponent.post(_request); } /* Step 4 - If the value is neither Retrieve or Post throw an exception */ throw new Exception("RequestHandler.process: Action passed is not a Retrieve or a Post"); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?