Sourav048
Sourav048

Reputation: 332

JSP - Pass a variable to servlet

How can i pass the value=x in to the servlet from the JSP? I searched for many related questions but could not get my answer. Here x is a variable.

<html>
<body>
<%@ page import="java.lang.*"%>
<%!int x,y; %>
<% String a,b;
a=request.getParameter("jobs");
b=request.getParameter("process");
x=0;
y=0;
try
{
 x=Integer.parseInt(a);
   y=Integer.parseInt(b);
}
catch(Exception e)
{ }
  out.println("You selected - <br>");
  out.println("Jobs - "+x+"<br>");
  out.println("Process - "+y);
   String path="table?input=x";
   %>

  <jsp:include page="table" > 
   <jsp:param name="input"  value=x/>
  </jsp:include>

</body>
</html>

Upvotes: 2

Views: 878

Answers (1)

Abdullah Shaikh
Abdullah Shaikh

Reputation: 2604

Since the variable x is within a scriptlet, you need to use <%= %>

<jsp:include page="table" > 
    <jsp:param name="input"  value="<%=x%>"/>
</jsp:include>

Upvotes: 5

Related Questions