Lucky
Lucky

Reputation: 111

Get param from html to java function call

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.

Upvotes: 1

Views: 1510

Answers (1)

BalusC
BalusC

Reputation: 1108762

 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");
// ...

Upvotes: 1

Related Questions