JSP an executing a code
This is pretty noob question, if I have an html button:
and when the user presses this button then I want the code in this jsp code to be run, how can I do thi开发者_如何转开发s? or the code that I want to run should be on another .jsp page?
I guess the only way to do this would to do am a href to itself in the button?
The web has the request/response lifecycle. So if you want to invoke server-side (jsp/servlet) code from client-side code (html), then you need to request a server resource. You can do that by either submitting a form, or by navigation (with a link or javascript) the URL to the target server resource.
There, you handle the request. It is preferable to do this in a servlet, and its doGet(..)
/ doPost(..)
method(s). And then you redirect to a view (jsp, which generates html) again.
It is strongly advisable to read a book or tutorial about servlets and jsp before you start.
精彩评论