开发者

access html components in servlet

so i am using java servlets to response to a request from a jsp page. and i want to change the html components name on that jsp page, like i change the buttons value or hide a label.i am wondering if there is any way to access jsp pag开发者_如何转开发e's HTML components like button, text, ... in a servlet ? i want to return the response in the same page that i have got the requests from. can i just simply write

 button1.name = "john"
or text1.value = "ross geller" ?


Short answer is "no", longer answer is:

Firstly, you have to understand that HTTP and servlets is not an event-driven GUI like a desktop client, it's a lifecycle oriented, request/response paradigm. What this means is that the client (browser) makes a request for a page. The server (servlet) then responds with the HTML for that page. Once the servlet has sent the HTML to the browser, there is nothing that can be done on the server to change it, unless the browser makes a new request.

In this very basic paradigm, the lifecycle might look something like this:

A request is made by posting a form (browser) -> request is received (servlet) -> servlet does some processing based on request parameters -> HTML is generated (either by the servlet or by forwarding to a JSP page) -> HTML is sent back to the browser -> browser renders the page from the HTML

This is a very basic example, there are many variations on this based on which framework you use but they all boil down to something along these lines.

So, in your case, you have a page with, presumably, a form on it that has a button. You want to post that form and then return the same page but with some other label on the button. In the lifecycle abovem you would extract the parameters posted on the form from the request (paramters=all fields on the form). Then, in the HTML generation, you would use those request parameter values when building the HTML. I would advice you to search the web for some tutorials on servlet technology and look at some examples you might find and this will become clearer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜