• Post Reply Bookmark Topic Watch Topic
  • New Topic

reference Bean from Servlet

 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Here's the situation: I'm dynamically filling in a pdf form, which will be viewed by a user. Now, all the data to fill in the form (i.e. name, age, dob, etc.) is stored in a Bean. I'd like to use JSP alone to do this, but I can't seem to get the JSP page to bring up the pdf file. I'm using the FDF Toolkit to process the data, but this really isn't relevant to the problem. It's more of a JSP issue, primarily with response object.
I'm trying the following:

This code will not bring up the respective pdf. However, if I use similar logic in a servlet, it will work. My questions are:
1.) How can I direct the response in this JSP page to bring up the pdf? The line outFDF.Save(output) writes to the outputstream, but the pdf is not coming up.
2.) Can I reference this Bean from a Servlet in order to avoid the extensive parameter passing?
Thanks everyone for your input,
WS
[ February 06, 2004: Message edited by: Winston Smith ]
[ February 06, 2004: Message edited by: Winston Smith ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However, if I use similar logic in a servlet, it will work.

My question would be, since you've already gotten this working via a servlet, which is the most appropriate technology for the purpose, why do you feel a need to shoehorn this into a JSP which, being a technology designed to deliever text responses, is ill-suited to the task?
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the main reason I'd like to use JSP is simply because I have direct access to the Bean. I am going the servlet route, designing a servlet to populate and display the pdf form, and the main question is, how do I reference a Bean object in a servlet. I have found the following, which I believe will do the trick:
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you show for getting a bean looks ok, but:
  • Are you sure you want to use the application context here? Usually things such as filled in form information really belong in the session context: MyBean bean = (MyBean)request.getSession().getAttribute("name");
  • I don't think you want to fetch your bean from the servlet "init" method. This is called when the servlet is first loaded, not necessarily when the rest of the application is running. I suggest you fetch the bean at the start of the doGet method.

  •  
    Winston Smith
    Ranch Hand
    Posts: 136
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the advice, Frank. I'm referencing the Bean in the doPost method. I didn't realize the getServletContext() is in the application scope, but it makes sense. Thanks for the example -- it clarified things for me!
    WS
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!