I've written up a few servlets to mimick the handling of login requests in order to开发者_高级运维 more understand how this communication works, aswell as how the creation and managing of cookies is done.
However, I find myself caught with a unrelated question for you all; As I'm simply redirecting my users to static html pages for login success or failure (and not writing them out from within the servlet to the HTTPResponse), is there a better way to add dynamic content (a simple message, for example, that will let the user know that he has logged in but a certain error has occurred) into a static HTML page that the user is being redirected to by the servlet, other than simply adding 'parameters' to the URL and the page treating these parameters?
Maybe making the static HTML page a JSP page, would it offer a way to handle this? I'm simply trying to avoid having to write a new HTML page for each possible errors that could occcure. Also, if possible I'd like to avoid having to write out HTML in the servlet directly to the HTTPResponse.
Thanks!
Yes- that's indeed a function of a JSP. You would turn your HTML into a JSP that can then display dynamic content that you set on the response, and embeds it where you need it in the final HTML.
There are framework that make this type Model-View-Controller web applications easy to manage and develop, such as Spring MVC, Struts 2, and the Stripes Framework. If this is a new project you are developing, I highly recommend using one of these frameworks as it will make your life much easier going forward.
精彩评论