Servlet本身就是一个class,通过new一个实例,调用其中的doPost(),doGet(),destory().....方法
解决方案 »
- 有谁用过pushlet吗?
- 关于备份数据库的问题,是否只能在数据库服务器上面备份?
- Can not find the tag library descriptor for "http://struts.apache.org/tags-bean"
- struts2 日期控件默认显示
- java string搜索问题?都来瞧瞧
- 如何通过hibernate创建一个有自增列和主键列的表?
- struts2中,在页面上如何点击弹出一个小窗口,里面是一个文本框,显出action中的一个参数值
- webshpere,structs,spring,Hiber,JSF,EJB等问题
- hibernate中如何实现非主键的一对多的关系?
- hibernate保存的问题
- 在Weblogic上配置Hibernate为JNDI时出现错误!急!!在线等待!
- 返回值的问题
Servlet可被链接(chain)。一个Servlet可以调用另一个或一系列Servlet,即成为它的客户端。 但我不知道如何做
voi init(ServletConfig cfg){
context.setAttribute("serv", this);
}Servlet s = (Servlet)application.getAttribute("serv");
当然,可以考虑加上判断它是否为空的语句。
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.util.ArrayList;/**
* 客户端调用servlet的类,参数用对象的方式传递,servlet的返回也是java对象
* User: zhouhb
* Date: 2003-7-30
* Time: 15:51:14
* To change this template use Options | File Templates.
*/
public class ClientRequest { private static URL servletURL; public static void setCodeBase(URL codeBase)
throws ClientRequestException {
try {
servletURL = new URL(codeBase.getProtocol(), codeBase.getHost(), codeBase.getPort(), codeBase.getFile() + "/xmlquery");
} catch (MalformedURLException e) {
e.printStackTrace();
throw new ClientRequestException(e);
}
} public static ArrayList sendRequst(int cmd, ArrayList params)
throws ClientRequestException {
ArrayList results = new ArrayList();
try {
URLConnection servletConnection = servletURL.openConnection(); //建立与Servlet的联接 servletConnection.setDoOutput(true); //用于写数据
servletConnection.setUseCaches(false); //这次连接不用Cache ObjectOutputStream oos = new ObjectOutputStream(servletConnection.getOutputStream());
oos.writeInt(cmd); int paramCount = params.size();
oos.writeInt(paramCount);
for (int i = 0; i < paramCount; i++) {
oos.writeObject(params.get(i));
}
oos.flush(); ObjectInputStream ois = new ObjectInputStream(servletConnection.getInputStream());
int resultCount = ois.readInt();
for (int i = 0; i < resultCount; i++) {
Object ob = ois.readObject();
results.add(ob);
}
return results;
} catch (IOException e) {
e.printStackTrace();
throw new ClientRequestException(e);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new ClientRequestException(e);
}
}}