I have a simple JSP question, and you will have to forgive me because I know this has been answered on these forums before, but I can't seem to get them to work for my application.
I have a series of check boxes, text boxes, and radio buttons in a form. What I'd like for is when the user submits the form on one "test.jsp" page, these parameters are added to the URL query string and are present on the submitted page "result.jsp", such as:
Can I write a JS function that builds the URL parameters, then just append it to the action="result.jsp" when submitted? I would consider this a dirty solution, but what would the action="" look like if you want to call a JS function that does this? Can you submit a form within JS?
Joined: Jun 21, 2012
Thanks! Using the get method showed exactly what I needed .. then I could just use <% request.getParameter("name") %> to build my result.jsp page with these parameters. Doing it this way matters to me only for learning, which I hope is not an issue here?
Thanks for the advice. I'll mark this one resolved.
andy kra wrote:Using the get method showed exactly what I needed .. then I could just use <% request.getParameter("name") %> to build my result.jsp page with these parameters.
Three important points here:
Regardless of whether you use get or post, and regardless of whether the parameters are passed on the URL or in the post body, you fetch the parameters the same way.
Constructs such as <% request.getParameter("name") %> in a JSP are an extremely poor practice that has been discredited for over 10 years now. Whatever you are using as a JSP tutorial is very out of date if it is not directing you to use the JSTL and EL instead of Java scriptlets.
Submitting a form to a JSP page is another no-no. Always submit data for processing to a servlet. A JSP is for view generation only.
Doing it this way matters to me only for learning, which I hope is not an issue here?
If you are just learning, you are definitely heading down the wrong path, using antiquated and discredited techniques. Modern JSPs should contain no Java code.