Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp bean problem

 
mitforu patel
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all....I am using a jsp and bean.. i m using the bean to initialize a variable and using a jsp page to retrive the value.... but when i try to initialize the variable using a setX() method then the requesting jsp page will get the value 0. here is the program.

testBean.java



the controlling servlet is :


and the jsp page is :




i searched a lot but i cant get through this problem. any ideas?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few things.
  • You should indent your code properly. Unindented code looks ameteurish and is hard to read.
  • You should not do useless actions in your code. Why do you fetch the output writer and never use it? Confusing and a source of potential problems.
  • You set an instance of the bean in the session, and then create a new one. Of course the value set in one instance won't be available in the other.


  •  
    mitforu patel
    Greenhorn
    Posts: 11
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sir can you please tell what should i modify in this code so that it can work properly? thank you
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64171
    83
    IntelliJ IDE Java jQuery Mac Mac OS X
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Think about it.

    You create a bean in the servlet and place it as a scoped variable in the session.

    What do you need to do on the JSP page to hook up to it with <jsp:useBean>? How can the JSP know how to find it?

     
    mitforu patel
    Greenhorn
    Posts: 11
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    do I need to recall the session?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64171
    83
    IntelliJ IDE Java jQuery Mac Mac OS X
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Let's try another tactic. If I name a dog "Spot" and want him to come home for dinner, would I call for "Rover"?
     
    mitforu patel
    Greenhorn
    Posts: 11
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I got it..... thank you very much......
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic