• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp bean problem

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    do I need to recall the session?
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I got it..... thank you very much......
    reply
      Bookmark Topic Watch Topic
    • New Topic