Results 1 to 5 of 5
  1. #1
    saurabh1989 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Checking if a variable is set in jsp

    Is there any function in jsp to check whether a variable passed from other page is set or not as in PHP it is isset()
    Thank you:

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    I think you should clarify what you mean by 'passed'...I presume you mean via a query string, in which case you grab the value from the request object and if it is null it has not been 'passed'

  3. #3
    saurabh1989 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    ya like for example i am passing the value of a text box(say name) from a html page to handle it in a jsp page.
    then i want to know how would i check that if its value is set or not

  4. #4
    murali.java is offline Member
    Join Date
    Oct 2010
    Posts
    7
    Rep Power
    0

    Default

    One thing You should remember . When ever you are making a request with values from client(ex:html) to server(ex:jsp),make sure that all the values are set and then send the request to the server,because we should not load the server with bad request.

    So you need to perform client side validation before sending the request to the client.Client side validations can be done by using Java Scripts.

    And coming to your question

    html file
    ----------
    <form action="two.jsp" method='post'>
    name:<input type='text' name='name'>
    </form>


    two.jsp
    ---------
    <%
    String req_name=request.getParameter("name");
    //if name filed is not set then value of the string "req_name" is null

    if(name==null)
    {
    //value is not set

    }else
    {
    //value set

    }
    %>

  5. #5
    saurabh1989 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

Similar Threads

  1. how to do checking value
    By madhuks in forum Java Servlet
    Replies: 3
    Last Post: 07-21-2010, 09:35 AM
  2. Replies: 11
    Last Post: 07-07-2010, 06:02 AM
  3. Checking udppackets in xp
    By abdullahansari in forum New To Java
    Replies: 1
    Last Post: 05-25-2010, 03:48 AM
  4. Checking if a file name already has .txt in it
    By AJArmstron@aol.com in forum New To Java
    Replies: 2
    Last Post: 04-17-2010, 12:45 PM

Posting Permissions

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