/* $Id: CookieExample.java,v 1.2 2001/06/11 22:49:11 craigmcc Exp $
*
*/
package examples.servlets;
import java.sql.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import commonServlet.CmRequestPatten;
import sample.*;/**
* Example servlet showing request headers
*
* @author James Duncan Davidson <[email protected]>
*/public class CommonServlet extends HttpServlet { protected ServletConfig servletConfig;
protected ServletContext servletContext; public void init(ServletConfig argServletConfig)throws ServletException {
super.init(argServletConfig);
servletConfig = argServletConfig;
servletContext = argServletConfig.getServletContext();
} public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String applicationClass = (String)request.getParameter("applicationClass");
String worningPage = (String)request.getParameter("worningPage");
String nextPage = (String)request.getParameter("nextPage");
String excuteType = (String)request.getParameter("excuteType");
HttpSession session = request.getSession(false);
try {
if (applicationClass != null && applicationClass.trim().length() != 0) {
CmRequestPatten application = (CmRequestPatten)Class.forName(applicationClass).newInstance();
application.setHttpRequest(request);
application.setHttpResponse(response);
application.setHttpSession(session);
application.setServletConfig(servletConfig);
application.setServletContext(servletContext);
if (excuteType.equals("select")) {
application.selectData();
} else if (excuteType.equals("insert")) {
application.insertData();
} else if (excuteType.equals("updata")) {
application.updata();
} else if (excuteType.equals("delete")) {
application.deleteData();
} else {
getServletContext().getRequestDispatcher(worningPage).forward(request,response);
}
} else {
getServletContext().getRequestDispatcher(worningPage).forward(request,response);
} } catch (Throwable ex) {
System.out.println(ex);
getServletContext().getRequestDispatcher(worningPage).forward(request,response);
}
getServletContext().getRequestDispatcher(nextPage).forward(request,response);
} public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}}
*
*/
package examples.servlets;
import java.sql.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import commonServlet.CmRequestPatten;
import sample.*;/**
* Example servlet showing request headers
*
* @author James Duncan Davidson <[email protected]>
*/public class CommonServlet extends HttpServlet { protected ServletConfig servletConfig;
protected ServletContext servletContext; public void init(ServletConfig argServletConfig)throws ServletException {
super.init(argServletConfig);
servletConfig = argServletConfig;
servletContext = argServletConfig.getServletContext();
} public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String applicationClass = (String)request.getParameter("applicationClass");
String worningPage = (String)request.getParameter("worningPage");
String nextPage = (String)request.getParameter("nextPage");
String excuteType = (String)request.getParameter("excuteType");
HttpSession session = request.getSession(false);
try {
if (applicationClass != null && applicationClass.trim().length() != 0) {
CmRequestPatten application = (CmRequestPatten)Class.forName(applicationClass).newInstance();
application.setHttpRequest(request);
application.setHttpResponse(response);
application.setHttpSession(session);
application.setServletConfig(servletConfig);
application.setServletContext(servletContext);
if (excuteType.equals("select")) {
application.selectData();
} else if (excuteType.equals("insert")) {
application.insertData();
} else if (excuteType.equals("updata")) {
application.updata();
} else if (excuteType.equals("delete")) {
application.deleteData();
} else {
getServletContext().getRequestDispatcher(worningPage).forward(request,response);
}
} else {
getServletContext().getRequestDispatcher(worningPage).forward(request,response);
} } catch (Throwable ex) {
System.out.println(ex);
getServletContext().getRequestDispatcher(worningPage).forward(request,response);
}
getServletContext().getRequestDispatcher(nextPage).forward(request,response);
} public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}}
解决方案 »
- 能帮我看下这个异常是什么原因才会出现的吗
- 如何用hibernate实现跨oracle数据库操作?
- 求一正则
- 一个超难题,请高手指教
- 一家公司的测试题,很急,谢谢!
- 怎么得到TOMCAT关闭的通知,或者说进程关闭的通知当然更好.
- 阻止session第三方cookie的问题(急)
- 各位大侠,新年好!请问哪里有Jbuilder电子书籍下载?
- 我的的ejb已经布署,但为什么总是说找不到包<%@ page import="bmp1.*" %>有问题
- maven搭建mybatis报错:Could not find resource
- 请教怎么处理entity bean中findAll()返回的结果集??!!
- 问一个比较菜的问题
*
*/
package sample;
import ejb.*;
import commonServlet.CmRequestPatten;
import java.sql.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import datasource.sampleDataSource;import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import java.lang.reflect.*;
import java.text.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
* Example servlet showing request headers
*
* @author James Duncan Davidson <[email protected]>
*/public class samplesource extends samplesource0 { protected static final String ENV_ENTRY_ENVIRONMENT_FILE = "ome.Properties";
protected String rootUri;
protected Vector environmentList = new Vector();
protected HashMap includeFileMap = new HashMap(); public samplesource() {
} public void selectData() throws Throwable { String homeName = (String)httpServletRequest.getParameter("jNDIHomeName");
String homeInterfaceName = (String)httpServletRequest.getParameter("ejbHome");
Class homeInterface = null;
if (homeInterfaceName != null) {
try {
homeInterface = Class.forName(homeInterfaceName);
} catch (ClassNotFoundException ex) {
}
}
EJBHome home = null;
try {
Object homeObject = getInitialContext().lookup(homeName);
if (homeInterface == null) {
homeInterface = homeObject.getClass();
}
home = (EJBHome)PortableRemoteObject.narrow(homeObject, homeInterface);
} catch (NamingException ex) {
//名前が適切でない場合 } Method homeMethod = home.getClass().getMethod("create", new Class[]{}); EJBObject remote = (EJBObject)homeMethod.invoke(home, new Object[]{});
List list = null;
if (remote instanceof ejbsample) {
list = ((ejbsample)remote).selectData(httpServletRequest);
}
httpServletRequest.setAttribute("result" ,list);
} private Context getInitialContext() throws NamingException {
try {
// Get an InitialContext
String url = servletConfig.getInitParameter("EJBProviderURL");
String EJBInitialContextFactory = servletConfig.getInitParameter("EJBInitialContextFactory");
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, EJBInitialContextFactory);
h.put(Context.PROVIDER_URL, url);
return new InitialContext(h);
} catch (NamingException ne) {
throw ne;
}
}}
例如:在一个用户验证的servlet中,如果用户验证成功,则打开success.html,否则打开error.html
if ok response.sendRedirect("ok.html") else response.sendRedirect("error.html");
2 在一个ejb中如何调用另一个ejbHashtable ht = new Hashtable();
ht.put(ctx.PROVIDER_URL, "t3://ip:port");
ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ctx = new InitialContext(ht);
anEJBHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow (ctx.lookup (homeClass.getName()), homeClass);
3 在一个servlet中如何调用另一个servlet
没这么调的.没试过
4 在一个jsp中如何调用另一个jsp
<%@ include file="xxx.jsp" %>
还有一种,没有用过,懒得找了 :)