GeeCON Prague 2014*
The moose likes JSP and the fly likes jsp bean problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "jsp bean problem" Watch "jsp bean problem" New topic
Author

jsp bean problem

mitforu patel
Greenhorn

Joined: Jan 13, 2010
Posts: 11
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

Joined: Jan 10, 2002
Posts: 61315
    
  66

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.



  • [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    mitforu patel
    Greenhorn

    Joined: Jan 13, 2010
    Posts: 11
    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

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    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

    Joined: Jan 13, 2010
    Posts: 11
    do I need to recall the session?
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    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

    Joined: Jan 13, 2010
    Posts: 11
    I got it..... thank you very much......
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: jsp bean problem