我在链接 HTML 和 JSP 时遇到问题。只是想制作一个简单的 html 页面来获取“电子邮件”和“密码”,然后在下一页显示 jsp。但是当我点击提交时,参数没有被传递,我只是得到“null”,我有什么地方出错了吗?
HTML 页面
<html>
<head>
<title>Enter your email and password</title>
</head>
<body>
<form action="form.jsp" method="get">
<table cellspacing="5" border="0">
<tr>
<td align="right">Email:</td>
<td><input type="text" email=email></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="text" password=password></td>
</tr>
<tr>
<td></td>
<td><br><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
JSP 页面
<html>
<body>
<%
// get info from request
String email = request.getParameter("email");
String password = request.getParameter("password");
%>
<p>Here is the info you provided:</p>
<table cellspacing="5" cellpadding="5" border="1">
<tr>
<td align="right">Email:</td>
<td><%= email %></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><%= password %></td>
</tr>
</table>
<form action= "Next" method="post">
<input type="submit" value="Return">
</form>
</body>
</html>
最佳答案
您需要在表单字段中使用 name
属性。
<input type="text" name="email"></td>
“email”的值可以在 JSP 中检索为:
String email = request.getParameter("email");
或
${param.email}
或
<c:out value="${param.email}"/> <%--(Using JSTL)--%>
这是 complete list属性。
名称=字符串#
为了提交表单而与此元素关联的名称/值对的名称部分。
关于java - 将 HTML 链接到 JSP 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16756528/