这是一个带有表单的示例 jsp 页面。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="h.abc" %>
<%
abc p = new abc();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="abcd.jsp" method="POST">
<input type="hidden" name="<%=p.getName()%>+'Name'" value='y'>
<input type='text' name='<%=p.getName()%>' >
<input type='submit' value='submit'>
</form>
</body>
</html>
这是'h'包中的abc类。请原谅命名。这仅用于说明目的。
public class abc {
public String name="abc";
public abc()
{
}
public String getName()
{
return name;
}
}
这是abcd.jsp目标页面。这里我试图获取输入字段的值。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="h.abc" %>
<%
abc p = new abc();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String s = p.getName();
out.println(request.getParameter(s+"Name"));
out.println(request.getParameter(s));
%>
</body>
</html>
我无法理解为什么输入字段没有返回“y”作为其值。而是返回 null。
最佳答案
更改第一个jsp中的代码
<input type="hidden" name="<%=p.getName()%>Name" value='y'>
关于java - java中如何获取名称等于方法和字符串的输入隐藏字段的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49606010/