Search code examples
jspservletshrefhttp-request-parameters

How to send two values in a jsp with this href code to another jsp?


I have one jsp called "first-jsp" containing this code:

<a href="./second-jsp.jsp?id=<% out.print(id); %>"><%out.print(id);%></a>

As you can see, first-jsp "sends" the id variable to another jsp page, called "second-jsp".

From second-jsp I can retrieve its value simply using:

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

I want to send the value of another variable to "second-jsp" (together with id).

Let's say I want to send the value of a String variable called "name" for example.

How the above code should be modified to achieve this?

I should be able to retrieve name similarly to id, using

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

So, I'm able to use both id and name in second-jsp.

Thanks!


Solution

  • you can pass two parameters

    <a href="./second-jsp.jsp?id=<% out.print(id); %>&name=<% out.print(name); %>"><%out.print(id);%></a>