Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    179
    Thanks
    17
    Thanked 0 Times in 0 Posts

    getParameter in JSP

    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
    Last edited by otnj2ee; 01-31-2008 at 01:38 AM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by otnj2ee View Post
    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

    Quote Originally Posted by otnj2ee View Post
    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
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    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.
    "To iterate is human, to recurse divine." -L. Peter Deutsch

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    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

    Code:
    request.setAttribute("id", "test");
    and in the JSP u can use

    Code:
    <&#37;
    String id = request.getAttribute("id");
    %>
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #5
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •