...

View Full Version : getParameter in JSP



otnj2ee
01-31-2008, 12:34 AM
I want to pass a parameter from the Java side to the JSP:

In the JSP I'll use the scriptlet to capture it, like this:

<&#37;
String id = request.getParameter("id");
%>

How can I set the "id" to a value of "test" from the java class side?

Thanks


Scott

shyam
01-31-2008, 08:32 AM
I want to pass a parameter from the Java side to the JSP:

In the JSP I'll use the scriptlet to capture it, like this:

<%
String id = request.getParameter("id");
%>

request.getParameter is not from java side !! id is passed through the HTTP post/get request that was initiated from the client-side



How can I set the "id" to a value of "test" from the java class side?


what are u trying to do exactly? u can create a Http request by using apaches http-client library

Aradon
01-31-2008, 10:45 PM
I think what he's trying to do is pass data between his java servlet and his jsp page. I'm no expert on jsp so I'll allow the others to answer that general question.

shyam
02-01-2008, 05:32 AM
if u want to have access to some value that is set in the servlet but has to be accessed in the JSP to which the servlet forwards control (using the request dispatcher)....then u can use request attributes...

in the servlet use


request.setAttribute("id", "test");

and in the JSP u can use


<&#37;
String id = request.getAttribute("id");
%>

bhargavkumar_b
02-01-2008, 10:22 AM
hi,

This is in reply , that u have to pass a parameter from java class to JSP. If u want to get a value from java class, use <jsp:useBean> action , in that u can use it's "id" attribute . With that id , u have to call a method from java class, which returns a value.And that value, u can get in the JSP.
for example,in JSP

<jsp:useBean id="someid" class="somepackage.somejavaclass"></jsp:useBean>
...
...
....
someid.somemethod()
...


that method will return some value, and that value u can use.

cheers
BhargavKumar.B



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum