Thread: Variables

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    0
    Rep Power
    0

    Variables


    Hello, I am just curious if a variable is not defined in the JSP page, but is passed through the URL if can be accessed in the page? For exampe:

    http://server/sample.jsp?variable=test

    <sample.jsp>
    <HTML>
    <%
    if (variable == "test") {
    out.println("Variable = test\n");
    }
    %>
    </HTML>
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    5
    Rep Power
    0
    A variable doesn't appear automatically like it does in php. You can grab a query string variable like this:

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

    Also you can't test for string equality the way you did. if(variable == "test") would test if variable and "test" were the actual same object not just the same characters. you need if(variable.equals("test")) .

    outprintln() also includes a line return already so you don't need the \n
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    0
    Rep Power
    0
    Originally posted by jnicholas
    A variable doesn't appear automatically like it does in php. You can grab a query string variable like this:

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

    Also you can't test for string equality the way you did. if(variable == "test") would test if variable and "test" were the actual same object not just the same characters. you need if(variable.equals("test")) .

    outprintln() also includes a line return already so you don't need the \n
    ok thanks for the help, i appreciate it... but i have another question, does jsp allow you to encrypt objects in the query string... for example in coldfusion i could encrypt the value of variable with something like this :
    <CFSET variable2 = Encrypt(key, variable)>

    this just adds a little more peace of mind when dealing with user information.
  6. #4

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo