I'm working on a JSP app right now. I currently have made a button that launches a relative URL in a new window of a specific size using: onclick="window.open('./my_path','PREVIEW','width=600, height=300');
in the .jsp file. However I need some java code run within the Servlet before hand and I don't want to put any logic in the JSP file. Anyways I can do this?
EDIT: So the reason for this is because I want to do validation with javascript first, currently that's in the jsp. After validation I'd like to process something on the server, then I'd like to open a new window based on the server process.
Think
<input type="submit" name="Function" onclick="javascriptFunction()" style="WIDTH: 130px" value="Edit">
in the JSP. Then in the servlet doPost(...){ if(request.getParameter("Function"){//do something cool; //process open javascript window} }
The reason is that I need ordering to be maintained.
First of all if you included the relevant parts of the JSP, servlet, and web.xml that would be very useful. Any way I believe this may be close to what you are looking for.
Important concept is that the JSP is processed at the server. In fact the JSP is precompiled into a servlet. So if your uri resolves to myserv and then forwards the request to myjsp, it is forwarding the request to another servlet. The methods .setAttribute and .getAttribute are for the purpose of communicating between servlets at the server in the context of a request.
So assume you have web.xml roughly like this:
Then you have a servlet with doPost roughly like this:
Then you have a jsp with an expression tag roughly like this: