简体   繁体   English

JSP-将变量传递给servlet

[英]JSP - Pass a variable to servlet

How can i pass the value=x in to the servlet from the JSP? 如何从JSP将value = x传递到servlet? I searched for many related questions but could not get my answer. 我搜索了许多相关问题,但没有得到答案。 Here x is a variable. 这里x是一个变量。

<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>

Since the variable x is within a scriptlet, you need to use <%= %> 由于变量x在脚本中,因此您需要使用<%=%>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM