0

What I am using:

I am using java, eclipse and jsp project.

I think there is error is cause of missing jar file. I have added the Servlet.jar file but I think I also need a jsp.jar or jslt.jar file.

Error:

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

An error occurred at line: 15 in the jsp file: /ex01_2.jsp
 Bean01 cannot be resolved to a type

15:     <jsp:useBean id="userBean" class="Bean01" />

code:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JSTL Bean</title>
</head>
<body>
<!-- JSLT tage are "jsp:userBean" or "jsp:setProperty">
<!-- setProperty = set Bean01.java variables -->
<!-- getProperty = get Bean01.java variables -->

<!-- jsp:useBean = tells jsp that Bean01.java file is a bean -->
<!-- id = variable name -->
<jsp:useBean id="userBean" class="Bean01" />

<jsp:setProperty name="userBean" property="personName"
    value='<%=request.getParameter("personName")%>' />

<jsp:setProperty name="userBean" property="hoursWorked"
    value='<%=Double.parseDouble(request.getParameter("hoursWorked"))%>' />

<jsp:setProperty name="userBean" property="houlyWage"
    value='<%=Double.parseDouble(request.getParameter("houlyWage"))%>' />

<!-- output -->
<p>
    Person Name:
    <jsp:getProperty name="userBean" property="personName" />
</p>
<p>
    Hours Worked:
    <jsp:getProperty name="userBean" property="hoursWorked" />
</p>
<p>
    Houly Wage:
    <jsp:getProperty name="userBean" property="houlyWage" />
</p>
<p>
    Salary:
    <jsp:getProperty name="userBean" property="salary" />
</p>
<p>
    Tax:
    <jsp:getProperty name="userBean" property="tax" />
</p>
</body>
</body>
</html>
user1924249
  • 540
  • 3
  • 13
  • 38
  • This is the jar you want: javax.servlet.jsp-api 2.0. And the class value in should be something like class="com.web.package-name" i.e. the exact location where your Bean01.java is located – smoggers Aug 08 '15 at 13:58
  • I have just added jar file from the following website: http://mvnrepository.com/artifact/javax.servlet/jsp-api/2.0 and I am using default package. but still getting the same error. I was wondering if I missed some thing? – user1924249 Aug 08 '15 at 14:12
  • I've figured out the problem: it's because the Bean is in the default package, it must go in another package than the default in order to be located and used within the jsp file. So follow the suggestion I made in my first comment. – smoggers Aug 08 '15 at 14:23
  • yes, I have added this new jar file inside /WEB-INFO/lib. and I just create a package and Path for Bean01.java is following: /MyJspProject/src/MyPackage/Bean1.java – user1924249 Aug 08 '15 at 14:23
  • if you are still having issues refer to this answer here: http://stackoverflow.com/questions/8329451/cant-use-jspusebean-bean-cannot-be-resolved-to-a-type – smoggers Aug 08 '15 at 14:27

0 Answers0