View page without JSTL

F

francan00

I have a page that prints out a record using an object that comes from
a servlet. I dont have JSTL (due to restrictions in my environment)
and need to show the JSP view without JSTL:

Here is the servlet part:

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{

AddressBook addressBook = new AddressBook();

List addressRows = addressBook.getAllAddresses();

request.setAttribute("addressRows", addressRows);

request.getRequestDispatcher("/WEB-INF/webpage/
view.jsp").forward(request, response);
}



JSP that works with JSTL:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<body>
<c:forEach var="row" items="${addressRows}">
${row.firstname}
${row.lastname}
</c:forEach>
</body>
</html>


Now my attempt to show the record without JSTL:
Code:
<%@page import="mypackagenamehere.*"%>
<html>
<body>
<%
out.println(new AddressBook().addressRows.toString());
%>
</body>
</html>


This gives me an error:
An error occurred at line: 29 in the jsp file: /WEB-INF/webpage/
view.jsp
Generated servlet error:
addressRows cannot be resolved or is not a field


Please advise how I can get this to work without JSTL in my Tomcat
4.1.3 container?
 
W

Wojtek

I have a page that prints out a record using an object that comes from
a servlet. I dont have JSTL (due to restrictions in my environment)
and need to show the JSP view without JSTL:

Here is the servlet part:

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{

AddressBook addressBook = new AddressBook();

List addressRows = addressBook.getAllAddresses();

request.setAttribute("addressRows", addressRows);

request.getRequestDispatcher("/WEB-INF/webpage/
view.jsp").forward(request, response);
}



JSP that works with JSTL:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<body>
<c:forEach var="row" items="${addressRows}">
${row.firstname}
${row.lastname}
</c:forEach>
</body>
</html>


Now my attempt to show the record without JSTL:
Code:
<%@page import="mypackagenamehere.*"%>
<html>
<body>
<%
out.println(new AddressBook().addressRows.toString());
%>
</body>
</html>


This gives me an error:
An error occurred at line: 29 in the jsp file: /WEB-INF/webpage/
view.jsp
Generated servlet error:
addressRows cannot be resolved or is not a field


Please advise how I can get this to work without JSTL in my Tomcat
4.1.3 container?[/QUOTE]

maybe: new AddressBook().addressRows().toString()

Note the two brackets after addressRows.
 
A

Arne Vajhøj

I have a page that prints out a record using an object that comes from
a servlet. I dont have JSTL (due to restrictions in my environment)
and need to show the JSP view without JSTL:
AddressBook addressBook = new AddressBook();
List addressRows = addressBook.getAllAddresses();
request.setAttribute("addressRows", addressRows);
request.getRequestDispatcher("/WEB-INF/webpage/
view.jsp").forward(request, response);
<%@page import="mypackagenamehere.*"%>
<html>
<body>
<%
out.println(new AddressBook().addressRows.toString());
%>
</body>
</html>

This gives me an error:
An error occurred at line: 29 in the jsp file: /WEB-INF/webpage/
view.jsp
Generated servlet error:
addressRows cannot be resolved or is not a field

Try:

<%
List addressRows = (List)request.getAttribute("addressRows");
for(int i = 0; i < addressRows.size(); i++) {
X row = (X)addresRows.get(i);
out.println(row.getFirstname());
out.println(row.getLastname());
}
%>

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Another Servlet/JSTL question 6
JSTL database access 0
JSTL error 1
JSTL forEach 7
JSTL newbie question 3
JSTL c:loop works but c:out doesn't 2
servlets and jsp doubt 10
cactus and servlet redirection 0

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top