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?
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.
Joined: Jul 15, 2003
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:
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.