1

I am working with a java generated dynamic webpage, and I'm printing links from a query to a JDO. But I don't understand how can I get and use the parameter from the url.

My html objects are printed like this

 print = print + "Nome:<a href='displayFotos?album="+results.get(i).nome+ "'>"+ 
 results.get(i).nome+ "</a></br>";

The results in having for example:

Nome:<a href='displayFotos?album=album1'>album1</a>

So, in my head when clicked it should be calling the address of the dynamic webpage album like this and should get the parameter. In this case it would be the album1.

  else if (address.indexOf("/dinamicas/album") != -1)   {
        String album = param1;
        System.out.println("did it work? "+album);
    }

And I have in the beginning of the class a general parameter that I use to get text from html forms.

  String param1 = req.getParameter("param1");

I understand this might be an easy question but I'm not getting there by myself.

6
  • 2
    querystrings (the part of the URI after the '?') get also written to the request object so you should be able to do req.getParam("album") and there's also request.getQueryString() Commented Jul 9, 2011 at 9:00
  • I'm not sure I am understanding the question... If you are asking how to get params from a request, then smeg4brains already addressed that (reques.getParameter("album")... Commented Jul 9, 2011 at 9:09
  • nice, both ways worked. If you answer it I will accept it immediately. Thank you Commented Jul 9, 2011 at 9:09
  • On a side note, you might consider using a StringBuilder instead of just string concatenation, plus, URL-Encoding, just in case the name of the album contains spaces, url-non-friendly characaters (&, ?) and so on... Commented Jul 9, 2011 at 9:11
  • Yeah, I wasn't getting the parameters of the request and what I was finding in web was using enumerations and some weird things that weren't working. But with the answer from semg4brains it works fine. Commented Jul 9, 2011 at 9:12

1 Answer 1

1
 Nome:<a href='displayFotos?album=album1'>album1</a>

Here, you're using a parameter name of album.

However, you're attempting to get it by a parameter name of param1. This does obviously not match.

 String param1 = req.getParameter("param1");

You need to use the same parameter name as is been definied in the request.

String album = req.getParameter("album");
// ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.