JavaScript & JSP

こ雲淡風輕ζ 提交于 2019-12-18 09:41:57

问题


Firstly, I have done my research and already know that JavaScript = client JSPs = server side. I don't want to waste your time.

My situation is that I want to execute JSP code from an event (not from a HTML form).

I have a HTML link (<a href="...">XXX</a>), which is NOT within <form> tags; it just an ordinary HTML link. Through Javascript, I will be able to get the href value and store it in a hidden input field. Instantly after this, I want to execute request.getAttribute("...") and pass the parameter between JSP pages.

I do now know how to do the latter part (i.e. getting the request.getAttribute code to instantly proceed after the Javascript code has executed.

Can anyone advise?

Thankyou, Lucas


回答1:


You can't run JSP code like this.

JSP code, as you said is run on the server side, so you can't really trigger it from the web browser.

If you are just trying to pass a parameter between JSP pages, you can add the parameter to the queryString of the URL when you call the second JSP, and within it use request.getAttribute().

Remember, JSP code is executed before the page is sent to the browser.

I hope this helps.



来源:https://stackoverflow.com/questions/868985/javascript-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!