• 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

PrintWriter out variable used in servlet and want to use in JSP

 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I have declared a variable as follows and used in another class used for model

and in the doPost method of the servlet
I write

this gives me CoyoteWriter in Apache when I debugged in eclipse
now when I write

I am not getting the desired output
the servlet forwards the request directly to JSP
but on JSP I am not getting the output of displayQuestion method which is as follows


what is the problem with out variable?


 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry Prasad, I didn't understand your question properly the first time.

What is the method displayQuestion() you invoke? I cannot find such in the CoyoteWriter class - did you add it?

What is the code of your JSP which is not giving you what you need?

Cheers!

For what I remember, the RequestDispatcher.forward(-) will leave the code below this line and do nothing with it - it just forwards the request to the JSP for processing.

I think you should do everything you really need to do in servlet before doing a forward. Or use include and leave the out-related statements as they are.

Cheers!
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well what you had striked down was the answer for me
now I understand that everything after forwarding the request to JSP nothing will be executed afterwords

but what I want is that
I have to call the displayQuestion() method from the servlet and display it on the JSP which has some additional design

a solution I am thinking about setting the attribute that displayQuestion returns and then get that attribute in JSP and access it
but is it a good practice to do that?
what is your opinion?
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, than it's good I didn't erase it firmly ;-)

IMHO that is definitely a good solution to create a bunch of data (attributes) you need to use (access) in your presentation layer.
Thanks to this you are creating loosely coupled design in which the presentation layer (JSP) and business logic layer / controller (Servlet) are less dependent on each other.

By calling a servlet method from the JSP you are creating an additional dependency. I guess you could call this method using scripting (which is ultimately bad) or move the servlet calling code into the EL function which could do the work if you really, really need this.

So, the bottom line is that in your case I would certainly go for the attribute setting in Servlet class and JSP which accesses it. :-)

Cheers!
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nice
that helped
I would definitely follow your advice

this is the first web application I am building and hence facing too much silly problems
but we fall and then we learn to stand up isn't it

learning is good
I will keep still asking silly questions
thanks
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad I could help :-)

It's just normal that when you read the book it seems so obvious and simple as you read it. You can even pass the certificate just basing on those information.

But when you face the real-life problems, start to actually develop an application, it seems like it's the first time you see some things, you begin to ask the questions, become confused and so on.

And besides, sometimes when you ask the question you might even realize that you already know the answer :-)

So please ask as many relevant questions as you want - it also stimulates the answerer to refresh his memory :-)
 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic