• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Calling one JSP from another JSP

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

i have two jsp

one.jsp
two.jsp


From "one.jsp" i invoke "two.jsp" by calling

two.jsp?value1=20&value2=100

I read the request parameters value1 and value2 in my two.jsp and print it

But in my Browser URL i get only http://localhost:8080/examples/two.jsp?

and not http://localhost:8080/examples/two.jsp?value1=20&value2=100. Why?

=================
one.jsp
<html>
<form name="navigate">
<table>
<tr>
<td on Click="move()"> 1
</td>
<tr>
</table>
</form>
<script>
function move()
{
document.navigate.action="/examples/two.jsp?value1=20&value2=80"
document.navigate.submit();
}
</script>
</html>
===================

two.jsp
<%
out.println(request.getParameter("value1"));
out.println(request.getParameter("value2"));
%>

===================
 
Srivatsan Santhanam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some one please help me out with the above issue.

there is a typo where i have writen onClick as 'on click'. Please ignore that.


Thanks
Srivatsan
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Default form submit method is GET.When one submits the form, form controls are passed as name-value pairs in the URL and any parameters which are included in the url are ignored.
To make it work, just add method="post" in the form tag and you can see value1 and value2 being passed in the url when you invoke any other jsp.
Alternatively, you can also use value1 and value2 as hidden fields and make the request.
 
Srivatsan Santhanam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

To make it work, just add method="post" in the form tag and you can see value1 and value2 being passed in the url when you invoke any other jsp.



I thought in POST, all ur request parameters will not be seen in URL

will this work?
in first jsp i set <hidden name='value1' value='20'> and in second jsp i read it as request.getParameter('value1')>
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving topic to the HTML/JavaScript forum.
 
author & internet detective
Posts: 42027
916
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srivatsan,
You are correct that POST parameters are not passed or seen in the URL. Also, I recall GET being the default. You might try making the method=get explicit to see if that helps.

Alternatively, you could try the POST as you suggested. Note that the syntax for a hidden field is:
<input type="hidden" name="name" value="value" >
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic