Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

include jsp in servlet

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that in servlets there is nothing like this for auto-setting a bean's properties:

<jsp:setProperty name="myBean" property="*" />

However, I thought I saw something online about getting the RequestDispatcher when in a servlet doPost() method and including a JSP (that contains the auto-populating jsp:setproperty tag) like this:




Is this a good idea? I'm guessing I wouldn't want to do a lot of output in that JSP (just have it set the bean's properties), partially because it seems like it could get messy. Or do I just check the response after that method to see if the JSP outputted anything?
 
Tim Hannaford
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if I understand the situation. Why would you want a servlet to call a JSP to set a bean? Its easier to set a bean with a servlet and forward it to a JSP.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you say is true. I'm talking about how if you POST from a JSP then you can use the jsp:setProperty to auto-set all of a bean's properties before you even reach the servlet or whatever it is you're POSTing to (it's handy). However, a servlet doesn't have that bit of shorthand, so you have to do it all manually. I seem to remember seeing someone use RequestDispatcher.include in a servlet to include the output of a JSP, and I was wondering if that would be a way to use the quick setProperty from within a servlet.

But I guess I'm showing how tired I've been the last couple of days, because there's no reason why if I'm posting from a JSP to a servlet that I can't still use the jsp:setProperty in the JSP from which I'm POSTing! :roll:
 
Larry Cryderm
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the servlet code the jsp creates (in the *.java file). Emulate that code in your servlet to set the values. Remember, jsp's turn into servlets and those "short cuts" in jsp code are expanded in the servlet that is executed.
 
chandana sapparapu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may not be a relevant answer, but can you post your form date to a jsp first?
That is, you have form.jsp, and you want to post it to a servlet.
My solution is have a setter.jsp,

form.jsp -> set using setter.jsp -> post it to servlet.

will that work for your problem?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic