Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

controller  RSS feed

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a index.jsp and controller.jsp
in index.jsp,
String[] info = new String[5];
//i insert some value
Myclass.setInfo(info);
in controller.jsp
and I will use
<jsp:useBean id="Myclass" scope="session" class="Myclass"/>
<jsp:setProperty name="myclass" property="*"/>
Myclass.getInfo() in the controller.jsp
and do some stuff and forward back to index.jsp
now I am using servlet and my controller is in java code.
in the java code(my new controller.java),
i try to do a Myclass myclass = new Myclass();
and Myclass.getInfo() doesn't work for sure, ( i am sure it's null)
what's the right way to do it?
Sorry I am typing it so badly. I really appreciated your suggestion
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jackie
When you create the instance of Myclass in the JSP you are giving it session scope so it creates an instance and stores it in the session with the name, Myclass, that you gave it. To use the same instance in another resource, a servlet in your case, you need to get the object from the session, like this:
Myclass info = (Myclass)sess.getAttribute("Myclass");
hope that helps
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!