0
votes

PWC6197: An error occurred at line: 15 in the jsp file: /searchresult.jsp PWC6199: Generated servlet error: cannot find symbol symbol: class Food location: class org.apache.jsp.searchresult_jsp

PWC6197: An error occurred at line: 15 in the jsp file: /searchresult.jsp PWC6199: Generated servlet error: cannot find symbol symbol: class Food location: class org.apache.jsp.searchresult_jsp

PWC6197: An error occurred at line: 22 in the jsp file: /searchresult.jsp PWC6199: Generated servlet error: cannot find symbol symbol: class Food location: class org.apache.jsp.searchresult_jsp

This is what I get after running my code any idea why? Does it has anything to do with my database?if not how do I solve it

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>   
        <p><b>Search Results</b></p>
        <hr/>
        <p>Search results for <b>"<%=session.getAttribute("searchterm")%>"</b></p>
        <hr/>


            <tr><th>Name</th><th>Price</th><th>Restaurant</th></tr>
            <%
            List<Food> searchResult = (List<Food>)
                    session.getAttribute("searchresult");
            if(searchResult == null || searchResult.size() <= 0)
            {
                %>
            <tr><td colspan="3">(No result is found)</td></tr>
            <%
            }
            else
            {
                for(Food food : searchResult)
                {
                    %>
                    <tr>
                        <td><%=food.getItemName()%></td>
                        <td><%=food.getprice()%></td>
                        <td><%=food.getrestaurant()%></td>
                    </tr>
                    <%
                }
            }
            %>  
    <hr/>
    </body>
</html>

This is my Food.Java

package sg.edu.nyp;

import java.io.Serializable;

/**
 *
 * @author VN7-517G-73XW
 */
public class Food implements Serializable{
    public static final long serialVersionUID = -1L;
    private String itemName;
    private double price;
    private String restaurant;

 public Food()
    {
    }

    public String getItemName() {
        return itemName;
    }

    public double getPrice() {
        return price;
    }

    public String getRestaurant() {
        return restaurant;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public void setRestaurant(String restaurant) {
        this.restaurant = restaurant;
    }

}
1

1 Answers

1
votes

You must add import to your JSP file

enter relevant package name instead of [package]

<%@ page import="sg.edu.nyp.Food " %>

and make sure Food class exists in context.

If use tomcat should be in WEB-INF/classes/sg/edu/nyp/Food.class or WEB-INF/lib inside jar under /sg/edu/nyp/Food.class