applet能否发送一个对象到jsp,如果可以的话,也许能解决上面的问题
解决方案 »
- 求poi 3.7jar包
- struts中标签与forward简单问题求助
- 如此复杂的页面,数据库表如何设计最好呢??(见图)
- JSP
- jsp使用 beans 不能编译的问题!在线等带 ,谢谢帮忙~
- 数据库驱动程序??
- jsp传值问题
- Hibernate 读取bean的配置meta信息,比如表列,精度,PKFK 非空默认等
- 做了个web应用打印控件,用了4Fang WEB 打印控件,免费
- cookie一般会回写哪些内容?
- 有谁知道tomcat解析jsp和servlet具体是怎样的过程?参加者有分。
- tomcat如何将Tomcat-Standalone模式转化为Tomcat-Apache模式?在线给分
String result = .....; PrintWriter out = new PrintWriter(resp.getWriter());
out.write(result);
out.flush();
out.close();下面附上我处理applet和servlet数据接口。传输序列化对象,用ArrayList封装。
servlet:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(req.getInputStream())); String strAction = (String)ois.readObject();
ArrayList inList = (ArrayList)ois.readObject();
ois.close(); ArrayList outList = processPostAction(req,strAction,inList); ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(resp.getOutputStream()));
oos.writeObject(outList);
oos.flush();
oos.close(); } catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}applet:
private ArrayList sendMessage(String name,ArrayList list) throws Exception {
URL url = new URL(strBaseUrl); URLConnection con = url.openConnection(); //Initialize the connection
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(true); //Set the content that we are sending
con.setRequestProperty("Content-type", "application/octet-stream"); //Get the output stream to the server and send our data buffer
ObjectOutputStream oos = new ObjectOutputStream(
new BufferedOutputStream(con.getOutputStream()));
oos.writeObject(name);
if(list == null) {
list = new ArrayList();
}
oos.writeObject(list); //Flush the output stream and close it
oos.flush();
oos.close(); //Get the input stream we can use to read the response
ObjectInputStream ois = new ObjectInputStream(
new BufferedInputStream(con.getInputStream())); ArrayList retList = (ArrayList)ois.readObject(); //Close the input stream
ois.close(); return retList;
}
2.test.xsl好像要在webapps下找吧,不清楚。3。
con.setRequestProperty("Content-type", "application/octet-stream");
就会触发servlet的doPost动作。
非常感谢,对于第2个问题,需要使用getRealPath来确定路径
对于第1个问题,你的servlet接收了一个ArrayList对象,经过处理后又向applet返回了一个ArrayList对象,这样做是没有问题的,但我的servlet接收一个对象后,经过处理,在服务器端生成了一个htm临时文件(每次调用servlet都要生成一个临时文件,服务器上有太多的垃圾),所以我就想生成一个数据流,直接发送到applet,但是applet如何接收呢?接收到以后该如何处理呢?
servlet发送htm数据
String strHtm = ....;
PrintWriter out = new PrintWriter(new BufferedOutputStream(resp.getOutputStream()));
out.write(strHtm);
out.flush();
out.close();applet接收htm数据
...
URLConnection con = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(new BufferedInputStream(con.getInputStream())));
StringBuffer buff = new StringBuffer();
String str = null;
while((str = in.readLine()) != null) {
buff.append(str);
}
String strHtm = buff.toString();
in.close();
至于接收的strHtm要如何处理,就看你的业务逻辑了,只个我帮不上忙。