aspose file tools*
The moose likes JSP and the fly likes changing parmeter value in URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "changing parmeter value in URL" Watch "changing parmeter value in URL" New topic
Author

changing parmeter value in URL

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have a page with list of links. All the links have to open same page with
a list box and submit button. But for each link the submit will call different .do file.
For this

test.jsp
<a href="test1.jsp?rep=0">Report A</a>
<a href="test1.jsp?rep=1">Report B</a>

In test1.jsp
I am trying to see what is the value of rep and based on that I change the Form element dynamically. What I need is I don't want the user to go change the rep value in url to 0 or 1 or 2 or 3. How do I control this? Also, if he changes to rep value to other than 1 I want to redirect him to test.jsp page. how to do this

How do I do that?

[ August 26, 2004: Message edited by: shan javan ]
[ August 26, 2004: Message edited by: shan javan ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can not keep the user from changing the value in the addy bar.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Is there any other way I can do the whole thing
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Perhaps the best solution is a design change.

Consider this:
  • test.jsp contains a form with four links/buttons named ReportA to ReportD.
  • When a button/link is clicked, test.jsp is submitted to a controller servlet
  • The servlet identifies which button/link was clicked by checking a request parameter, sets the appropriate rep value and forwards the request to test1.jsp (or to separate JSPs for each report?)
  • test1.jsp then presents the appropriate report; you could perhaps look at using an include for that

  • The user never gets to see the report parameters in the URL.

    Does that help at all?

    Jules
    Anonymous
    Ranch Hand

    Joined: Nov 22, 2008
    Posts: 18944
    I do not have buttons in my page. Only have <a href> links. How do I know which link was clicked? Is there any flag that I can add thru javascript and pass it on to a hidden parameter...
    [ August 26, 2004: Message edited by: shan javan ]
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61766
        
      67

    No matter what you do in your pages, users are free to type whatever they want into the address bar (as Eric pointed out), or to write code that hits your page with whatever URL they'd like.

    Bottom line is, your code needs to be able to detect and deal with 'bad' values. If you are going to put web apps up on the Internet, there's no getting around it. Plain and simple.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Anonymous
    Ranch Hand

    Joined: Nov 22, 2008
    Posts: 18944
    Thats very true but atleast I don't want to append something like this to my url

    http://../test1.jsp?rep=0

    which will allow the user to change rep value.

    Something like this http://...//test1.jsp looks good to me.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61766
        
      67

    If you don't want to expose the req params in the URL, you need to submit via a POST (where the params are sent in the body of the response), or do some fancy footwork with frames (not a recommended approach).

    Bear in mind that anyone with an ounce of knowledge can still figure out what the params are even if you hide them from the address bar.
    [ August 26, 2004: Message edited by: Bear Bibeault ]
    Anonymous
    Ranch Hand

    Joined: Nov 22, 2008
    Posts: 18944
    test.jsp has two report links both opening to test1.jsp

    In test1.jsp I check rep value and based on that I change form element.

    <%
    String rep =request.getParameter("rep");
    int rep1 = Integer.parseInt(rep);
    out.println(rep1);
    if(rep1==0){
    out.println("<FORM METHOD= " +"POST " + "ACTION=" + "test2.jsp" + ">");
    }
    else if(rep1==1){

    out.println("<FORM METHOD= " +"POST " + "ACTION=" + "testi.jsp" + ">");
    }
    else{

    %>
    < jsp:forward page = "test.jsp">
    </jsp:forward>
    <%
    }
    %>


    I am trying to check if user tries to modify rep value .if rep is other that 1 or 0 I would like the user to be taken back to test.jsp.
    Somehow it does not work. Why?
    url looks like this

    http://../test1.jsp?rep=0

    [ August 26, 2004: Message edited by: shan javan ]
    [ August 26, 2004: Message edited by: shan javan ]
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61766
        
      67

    Somehow it does not work.


    My crystal ball is malfunctioning; what does 'does not work' mean exactly? What does happen?

    I'm also assuming that all the mistakes in your post that would cause the page to not compile are transcription errors? Please be careful when posting code that it is exactly like what you are really using so no one wastes time chasing those down. (For example, the lack of quotes in the forward action).
    [ August 26, 2004: Message edited by: Bear Bibeault ]
    Anonymous
    Ranch Hand

    Joined: Nov 22, 2008
    Posts: 18944
    I am sorry I missed "test.jsp" in my code too. The problem is it does not forward me to that page . It just displays the forwrd tag on the screen.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: changing parmeter value in URL