各位大哥救命 我在描述以下我的问题:步骤:1.用Servlet访问有状态会话Been给绘画Been的Vector里写入值并且已经写入正确2.用另外一个Servlet访问刚才的会话Been可是为什么Vector里为空 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我可以给你指出不对处在GetCarServlet中myCarHomeObject = (MyCarHome) PortableRemoteObject.narrow(ref, MyCarHome.class);myCarObject = myCarHomeObject.create();不正确;改为MyCarServlet 中加入session.setAttribute("shoppingCart", myCarObject);在GetCarServlet中使用myCarObject = (MyCar)session.getAttribute("shoppingCart");try{if(myCarObject!=null || myCarObject.getCarInfo()){ System.out.println("stored goods in this cart is exist!!!");}catch(Exception e){ //get a new cart without goods myCarHomeObject = (MyCarHome) PortableRemoteObject.narrow(ref, MyCarHome.class); myCarObject = myCarHomeObject.create();}java.util.Vector bookInfo; bookInfo = myCarObject.getCarInfo(); //Object ob[]; //ob = bookInfo.toArray(); Book carBook; carBook = (Book)bookInfo.get(0); out.println(carBook.BOOKNAME);//打印不出来 out.println(carBook.ID);)//打印不出来 //for(int i=0;i<ob.length;i++){ //carBook = (Book)ob[i]; //out.println(carBook.BOOKNAME); // }ok le 有几次错误,无法通过编译,其它还不知道,下面是改正后的package bookstoreejb;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import javax.naming.*;import javax.rmi.*;public class MyCarServlet extends HttpServlet { private static final String CONTENT_TYPE = "text/html; charset=GBK"; //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(); String ls_id = "1"; String url = "t3://127.0.0.1:7001"; MyCarHome myCarHomeObject = null; MyCar myCarObject = null; java.util.Vector lc_vectorBook; Book lc_Book; Properties properties = null; Context context = null; properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, url); try{ context = new InitialContext(properties); Object ref = context.lookup("MyCar"); myCarHomeObject = (MyCarHome) PortableRemoteObject.narrow(ref, MyCarHome.class); myCarObject = myCarHomeObject.create(); boolean good = myCarObject.addBook(ls_id);//添加到Vector lc_vectorBook = myCarObject.getCarInfo();//返回添加后的Vector lc_Book = (Book)lc_vectorBook.get(0); out.println("outname="+lc_Book.BOOKNAME);//信息已经打出 out.println("outid="+lc_Book.ID);//信息已经打出 if (good){ out.println("已经将书名为:《"+lc_Book.BOOKNAME+"》书籍,加入购物车!"); out.println("<meta http-equiv=refresh content=\"5;url=./tsxx.jsp?ifquest=false=false\">"); }else{ out.println("书名为:《"+lc_Book.BOOKNAME+"》书籍,您已经加入了购物车,不需要在加入!"); out.println("<meta http-equiv=refresh content=\"5;url=./tsxx.jsp?ifquest=false=/\">"); } }catch(Exception e){ e.printStackTrace(); } } //Clean up resources public void destroy() { }}package bookstoreejb;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import javax.naming.*;import javax.rmi.*;public class GetCarServlet extends HttpServlet { private static final String CONTENT_TYPE = "text/html; charset=GBK"; //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(); String url = "t3://127.0.0.1:7001"; MyCarHome myCarHomeObject = null; MyCar myCarObject = null; Properties properties = null; Context context = null; properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, url); try{ context = new InitialContext(properties); Object ref = context.lookup("MyCar"); myCarHomeObject = (MyCarHome) PortableRemoteObject.narrow(ref, MyCarHome.class); myCarObject = myCarHomeObject.create(); java.util.Vector bookInfo; bookInfo = myCarObject.getCarInfo(); //Object ob[]; //ob = bookInfo.toArray(); Book carBook; carBook = (Book)bookInfo.get(0); out.println(carBook.BOOKNAME);//打印不出来 out.println(carBook.ID);//打印不出来 //for(int i=0;i<ob.length;i++){ //carBook = (Book)ob[i]; //out.println(carBook.BOOKNAME); // } }catch(Exception e){ e.printStackTrace(); } } //Clean up resources public void destroy() { }} 关于类型转换问题 j2ee的学习 谁能解释下这个简单程序的运行结果 关于hibernate的问题 log4j:ERROR setFile(null,true) call failed. struts2 中的validation的运行原理是什么? Cookie 如何在webservice中调用Weblogic自带的身份验证机制? 300百分求解,关于resin3.0.10与IIS6的结合问题? 大家讨论下struts2小功能 有关Oracle数据库Blob类型JDBC操作4K限制的问题,高手请回答,下面代码有什么问题 JB9中EJB的deploy问题!!
在GetCarServlet中
myCarHomeObject = (MyCarHome) PortableRemoteObject.narrow(ref, MyCarHome.class);
myCarObject = myCarHomeObject.create();
不正确;
改为
MyCarServlet 中加入
session.setAttribute("shoppingCart", myCarObject);
在GetCarServlet中使用
myCarObject = (MyCar)session.getAttribute("shoppingCart");
try{
if(myCarObject!=null || myCarObject.getCarInfo()){
System.out.println("stored goods in this cart is exist!!!");
}
catch(Exception e){
//get a new cart without goods
myCarHomeObject = (MyCarHome) PortableRemoteObject.narrow(ref, MyCarHome.class);
myCarObject = myCarHomeObject.create();
}
java.util.Vector bookInfo;
bookInfo = myCarObject.getCarInfo();
//Object ob[];
//ob = bookInfo.toArray();
Book carBook;
carBook = (Book)bookInfo.get(0);
out.println(carBook.BOOKNAME);//打印不出来
out.println(carBook.ID);)//打印不出来
//for(int i=0;i<ob.length;i++){
//carBook = (Book)ob[i];
//out.println(carBook.BOOKNAME);
// }
ok le
package bookstoreejb;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.rmi.*;public class MyCarServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//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();
String ls_id = "1";
String url = "t3://127.0.0.1:7001";
MyCarHome myCarHomeObject = null;
MyCar myCarObject = null;
java.util.Vector lc_vectorBook;
Book lc_Book;
Properties properties = null;
Context context = null;
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url); try{
context = new InitialContext(properties);
Object ref = context.lookup("MyCar");
myCarHomeObject = (MyCarHome) PortableRemoteObject.narrow(ref, MyCarHome.class);
myCarObject = myCarHomeObject.create();
boolean good = myCarObject.addBook(ls_id);//添加到Vector
lc_vectorBook = myCarObject.getCarInfo();//返回添加后的Vector
lc_Book = (Book)lc_vectorBook.get(0);
out.println("outname="+lc_Book.BOOKNAME);//信息已经打出
out.println("outid="+lc_Book.ID);//信息已经打出
if (good){
out.println("已经将书名为:《"+lc_Book.BOOKNAME+"》书籍,加入购物车!");
out.println("<meta http-equiv=refresh content=\"5;url=./tsxx.jsp?ifquest=false=false\">");
}else{
out.println("书名为:《"+lc_Book.BOOKNAME+"》书籍,您已经加入了购物车,不需要在加入!");
out.println("<meta http-equiv=refresh content=\"5;url=./tsxx.jsp?ifquest=false=/\">");
} }catch(Exception e){
e.printStackTrace();
}
}
//Clean up resources
public void destroy() {
}
}package bookstoreejb;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.rmi.*;public class GetCarServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//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();
String url = "t3://127.0.0.1:7001";
MyCarHome myCarHomeObject = null;
MyCar myCarObject = null;
Properties properties = null;
Context context = null;
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
try{
context = new InitialContext(properties);
Object ref = context.lookup("MyCar");
myCarHomeObject = (MyCarHome) PortableRemoteObject.narrow(ref, MyCarHome.class);
myCarObject = myCarHomeObject.create();
java.util.Vector bookInfo;
bookInfo = myCarObject.getCarInfo();
//Object ob[];
//ob = bookInfo.toArray();
Book carBook;
carBook = (Book)bookInfo.get(0);
out.println(carBook.BOOKNAME);//打印不出来
out.println(carBook.ID);//打印不出来
//for(int i=0;i<ob.length;i++){
//carBook = (Book)ob[i];
//out.println(carBook.BOOKNAME);
// } }catch(Exception e){
e.printStackTrace();
} }
//Clean up resources
public void destroy() {
}
}