Solved

cannot be resolved to a type

Posted on 2006-07-19
11
5,210 Views
Last Modified: 2013-12-03
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.JasperException: 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
0
Comment
Question by:pmccar06
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
11 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 17137116
Check to see if the LoginBean is in a package. if it is provide the fully qualified name of the package.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17137117
Your class should normally be in a package
0
 
LVL 92

Expert Comment

by:objects
ID: 17137156
your class *must* be in a package
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 92

Expert Comment

by:objects
ID: 17137158
add a package statement to your class
move it to a directory that matches the package name
and include the package in the import
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17137334
class="packagename.LoginBean"
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17137345
even if the class is imported, fully qualified name is required in jsp:useBean tag
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 17137928
0
 

Author Comment

by:pmccar06
ID: 17145027
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(true);
     
      LoginBean loginBean = (LoginBean)session.getAttribute("loginBean");
      if (loginBean == null)
      {
         loginBean = new LoginBean();
         session.setAttribute("loginBean",loginBean);
      }
      loginBean.setEnteredUsername(strUsername);
      loginBean.setEnteredPassword(strPassword);      
         
     
      RequestDispatcher rd = context.getRequestDispatcher("/fo.jsp");
      rd.forward(req,res);      


   }

   public void doPost
      (HttpServletRequest req, HttpServletResponse res)
                    throws ServletException, IOException
   {
      doGet (req, res);
   }
}


Here is fo.jsp

<%@ page import="mypackage.LoginBean"%>
<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.JasperException: /fo.jsp(2,0) The value for the useBean class attribute mypackage.LoginBean is invalid.
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      LoginHandler.doGet(LoginHandler.java:30)
      LoginHandler.doPost(LoginHandler.java:39)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Have I got a class path issue?

Phil

0
 
LVL 92

Assisted Solution

by:objects
objects earned 60 total points
ID: 17145046
should be

<%@ page import="com.mypackage.LoginBean"%>
<jsp:useBean id="loginBean" class="com.mypackage.LoginBean" scope="session" />
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 65 total points
ID: 17145126
>> the 'com' folder I placed another folder 'mypackage' in which I placed LoginBean

Hope you mean LoginBean.class
0
 

Author Comment

by:pmccar06
ID: 17150331
Hi guys

Thanks for all your help, all problems fixed, you guys rock!

Cheers Phil
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question