1

Below code is an output.jsp to display the data submitted from submit.jsp in a format. I am fairly new to JSP and would like some guidance in how to pass paramaters firstname/lastname into html tags. Please advise . I have tried couple of approcahes with no success.

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

Here is the error that are thrown when running 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>
Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
z atef
  • 7,138
  • 3
  • 55
  • 50

2 Answers2

1

instead of <td><% firstname %></td> and <td><% lastname %></td> try <td><%= firstname %></td> and <td><%= lastname %></td>

gefei
  • 18,922
  • 9
  • 50
  • 67
  • Thanks, this was not suggested anywhere as missing = operator . Yes, it worked. Thanks @gefei – z atef Jan 12 '14 at 00:55
1

Apart from the fact that you're using an invalid scriptlet, they should be avoided

Try using instead

<td>${firstname}</td>

Related: How to avoid Java code in JSP files?

Community
  • 1
  • 1
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • thanks @Reimeus, while exploring jsp I came across EL as an option,but was not sure.... as I am trying to better my skill-set will def look into this. – z atef Jan 12 '14 at 01:06