Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling result.jsp (page 89 HFSJ)

 
Chris Jr
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting to call jsp from the servlet as described in page 89 of HFSJ. I get this error.

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 8 in the jsp file: /result.jsp
Generated servlet error:
styles cannot be resolved

The servlet class compiled without any error. Any ideas ...
 
Karen Jirak
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your result.jsp file?
 
Chris Jr
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. I am posting the result.jsp and the BeerSelect sevelet code. thanks.

<%@ page import="java.util.*" %>

<html>
<body>
<h1 align="center">Beer Recommendations JSP</h1>
<p>

<%
List Styles = (List)request.getAttribute("styles");
Iterator it = styles.iterator();
while(it.hasNext()){
out.print("<br>try: " + it.next());
}
%>

</body>
</html>


and the BeerSelect servelet code is :

package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class BeerSelect extends HttpServlet {
public void doPost (HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
//response.setContentType("text/html");

//PrintWriter out = response.getWriter();

//out.println("Beer Selection Advice<br>");

String c = request.getParameter("color");

// out.println("<br>Got beer color " + c);

BeerExpert be = new BeerExpert();
List result = be.getBrands(c);

// Iterator it = result.iterator();
// while (it.hasNext()) {
//out.print("<br>try: " + it.next());
// }

request.setAttribute("styles", result);
RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request, response);

}
}
 
Karen Jirak
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Chris,

In your scriptlet code in result.jsp, when you declare the list styles you capitalize it, but in the next line it starts with a lowercase "s". I think maybe fixing that should fix your problem.
 
Chris Jr
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are the man, Karen.

Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic