pmccar06
asked on
cannot be resolved to a type
Hi all
I have a jsp with a basic import statement at top:
<%@ page import="LoginBean"%>
<jsp:useBean id="loginBean" scope="session" class="LoginBean"/>
This class definately exists.
I can't figure out why tomcat returns the following error when I try to access that page:
org.apache.jasper.JasperEx ception: Unable to compile class for JSP
Generated servlet error:
The import LoginBean cannot be resolved
An error occurred at line: 2 in the jsp file: /loginPage.jsp
Generated servlet error:
LoginBean cannot be resolved to a type
If I remove the import statement, the problem goes away
Any help appreciated.
Phil
I have a jsp with a basic import statement at top:
<%@ page import="LoginBean"%>
<jsp:useBean id="loginBean" scope="session" class="LoginBean"/>
This class definately exists.
I can't figure out why tomcat returns the following error when I try to access that page:
org.apache.jasper.JasperEx
Generated servlet error:
The import LoginBean cannot be resolved
An error occurred at line: 2 in the jsp file: /loginPage.jsp
Generated servlet error:
LoginBean cannot be resolved to a type
If I remove the import statement, the problem goes away
Any help appreciated.
Phil
Check to see if the LoginBean is in a package. if it is provide the fully qualified name of the package.
Your class should normally be in a package
your class *must* be in a package
add a package statement to your class
move it to a directory that matches the package name
and include the package in the import
move it to a directory that matches the package name
and include the package in the import
class="packagename.LoginBe an"
even if the class is imported, fully qualified name is required in jsp:useBean tag
ASKER
Hi guys
You have got me on the track, but I still have issues. I created a folder called 'com' in the 'classes' folder for my application, and in the 'com' folder I placed another folder 'mypackage' in which I placed LoginBean.
LoginBean compiles ok as does my controller servlet that sets it.
Here is my bean:
package com.mypackage;
public class LoginBean
{
// attributes
String enteredUsername, enteredPassword, authenticatedUsername, message;
// constructor method
public LoginBean()
{
enteredUsername = "";
enteredPassword = "";
authenticatedUsername = null;
message = "";
}
// methods
public void setEnteredUsername(String enteredUsername)
{
this.enteredUsername = enteredUsername;
}
public void setEnteredPassword (String enteredPassword)
{
this.enteredPassword = enteredPassword;
}
public void setAuthenticatedUsername (String authenticatedUsername)
{
this.authenticatedUsername = authenticatedUsername;
}
public void setMessage (String message)
{
this.message = message;
}
public String getEnteredUsername()
{
return enteredUsername;
}
public String getEnteredPassword()
{
return enteredPassword;
}
public String getAuthenticatedUsername()
{
return authenticatedUsername;
}
public String getMessage()
{
return message;
}
}
Here is my servlet that sets this bean and calls the jsp
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import com.mypackage.*;
public class LoginHandler extends HttpServlet
{
public void doGet
(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
ServletContext context = getServletContext();
String strUsername = req.getParameter("username ");
String strPassword = req.getParameter("password ");
HttpSession session=req.getSession(tru e);
LoginBean loginBean = (LoginBean)session.getAttr ibute("log inBean");
if (loginBean == null)
{
loginBean = new LoginBean();
session.setAttribute("logi nBean",log inBean);
}
loginBean.setEnteredUserna me(strUser name);
loginBean.setEnteredPasswo rd(strPass word);
RequestDispatcher rd = context.getRequestDispatch er("/fo.js p");
rd.forward(req,res);
}
public void doPost
(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doGet (req, res);
}
}
Here is fo.jsp
<%@ page import="mypackage.LoginBea n"%>
<jsp:useBean id="loginBean" class="mypackage.LoginBean " scope="session" />
<html>
<head>
<title>FO Page</title>
</head>
<body>
<h3 align="center"><font face="Arial">FO Page</font></h3>
</body>
</html>
I now the tomcat error message:
org.apache.jasper.JasperEx ception: /fo.jsp(2,0) The value for the useBean class attribute mypackage.LoginBean is invalid.
org.apache.jasper.servlet. JspServlet Wrapper.ha ndleJspExc eption(Jsp ServletWra pper.java: 510)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 75)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:314)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:264)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
LoginHandler.doGet(LoginHa ndler.java :30)
LoginHandler.doPost(LoginH andler.jav a:39)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 709)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
Have I got a class path issue?
Phil
You have got me on the track, but I still have issues. I created a folder called 'com' in the 'classes' folder for my application, and in the 'com' folder I placed another folder 'mypackage' in which I placed LoginBean.
LoginBean compiles ok as does my controller servlet that sets it.
Here is my bean:
package com.mypackage;
public class LoginBean
{
// attributes
String enteredUsername, enteredPassword, authenticatedUsername, message;
// constructor method
public LoginBean()
{
enteredUsername = "";
enteredPassword = "";
authenticatedUsername = null;
message = "";
}
// methods
public void setEnteredUsername(String enteredUsername)
{
this.enteredUsername = enteredUsername;
}
public void setEnteredPassword (String enteredPassword)
{
this.enteredPassword = enteredPassword;
}
public void setAuthenticatedUsername (String authenticatedUsername)
{
this.authenticatedUsername
}
public void setMessage (String message)
{
this.message = message;
}
public String getEnteredUsername()
{
return enteredUsername;
}
public String getEnteredPassword()
{
return enteredPassword;
}
public String getAuthenticatedUsername()
{
return authenticatedUsername;
}
public String getMessage()
{
return message;
}
}
Here is my servlet that sets this bean and calls the jsp
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import com.mypackage.*;
public class LoginHandler extends HttpServlet
{
public void doGet
(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
ServletContext context = getServletContext();
String strUsername = req.getParameter("username
String strPassword = req.getParameter("password
HttpSession session=req.getSession(tru
LoginBean loginBean = (LoginBean)session.getAttr
if (loginBean == null)
{
loginBean = new LoginBean();
session.setAttribute("logi
}
loginBean.setEnteredUserna
loginBean.setEnteredPasswo
RequestDispatcher rd = context.getRequestDispatch
rd.forward(req,res);
}
public void doPost
(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doGet (req, res);
}
}
Here is fo.jsp
<%@ page import="mypackage.LoginBea
<jsp:useBean id="loginBean" class="mypackage.LoginBean
<html>
<head>
<title>FO Page</title>
</head>
<body>
<h3 align="center"><font face="Arial">FO Page</font></h3>
</body>
</html>
I now the tomcat error message:
org.apache.jasper.JasperEx
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
LoginHandler.doGet(LoginHa
LoginHandler.doPost(LoginH
javax.servlet.http.HttpSer
javax.servlet.http.HttpSer
Have I got a class path issue?
Phil
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi guys
Thanks for all your help, all problems fixed, you guys rock!
Cheers Phil
Thanks for all your help, all problems fixed, you guys rock!
Cheers Phil