• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changing parmeter value in URL

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not keep the user from changing the value in the addy bar.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any other way I can do the whole thing
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 18944
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 64715
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Anonymous
    Ranch Hand
    Posts: 18944
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 64715
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 18944
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 64715
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 18944
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic