gpt4 book ai didi

java - jsp中如何传递String参数?

转载 作者:行者123 更新时间:2023-11-30 04:04:35 27 4
gpt4 key购买 nike

下面的代码是一个output.jsp,用于以某种格式显示从submit.jsp提交的数据。我对 JSP 相当陌生,想要一些关于如何将参数名字/姓氏传递到 html 标签的指导。请指教 。我尝试了几种方法但没有成功。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<h>The first and last name are</h>
<%
String firstname = (String) request.getAttribute("firstname");
String lastname = (String) request.getAttribute("lastname");

//out.println(firstname + " " + lastname);
%>
<table>
<tr>
<td>First Name : </td><td><% firstname %></td>
</tr>
<tr>
<td>Last Name : </td><td><% lastname %></td>
</tr>
</table>
</body>
</html>

这是运行output.jsp时抛出的错误。

An error occurred at line: 20 in the jsp file: /output.jsp
firstname cannot be resolved to a type
17: %>
18: <table>
19: <tr>
20: <td>First Name : </td><td><% firstname %></td>
21: </tr>
22: <tr>
23: <td>Last Name : </td><td><% lastname %></td>


An error occurred at line: 23 in the jsp file: /output.jsp
lastname cannot be resolved to a type
20: <td>First Name : </td><td><% firstname %></td>
21: </tr>
22: <tr>
23: <td>Last Name : </td><td><% lastname %></td>
24: </tr>
25: </table>
26: </body>

最佳答案

而不是 <td><% firstname %></td><td><% lastname %></td>尝试<td><%= firstname %></td><td><%= lastname %></td>

关于java - jsp中如何传递String参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21069905/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com