Obviously
Obviously

Reputation: 21

Importing java class to jsp causing cannot be resolved to a type error

JSP code:

    <%@ page import = "action.LoginCheckAction" %>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");

    LoginCheckAction ls = new LoginCheckAction();
    ls.printSomething(username);
%>

Java class:

    package action;

public class LoginCheckAction{
    public LoginCheckAction(){
        super();
    }

    public void printSomething(String username){
        System.out.println(username);
    }
}

Another JSP file is sending post data to the JSP code posted here. I am trying to use the method available in my Java file that is located in another directory, inside the package action, however it keeps giving me a LoginCheckAction cannot be resolved to a type.

I tried importing action.* instead, and it did not work.

Can anyone please explain what the problem is?

Upvotes: 1

Views: 5039

Answers (4)

viper
viper

Reputation: 734

if you have build your project using maven, sometimes it's unable to compile classes and generate the war and jar file.Build the project to eclipse or netbeans project by :-

  1. Go to the directory of the project
  2. Hold shift and right click and click on open command prompt here
  3. Type mvn eclipse:eclipse if you want to build the project for eclipse IDE or mvn netbeans:netbeans if you want to build the project for netbeans
  4. Close and open the project and your errors should be resolved

Upvotes: 0

oldvipera
oldvipera

Reputation: 315

if you have build your project using maven, sometimes it's unable to compile classes and generate the war and jar file.Build the project to eclipse or netbeans project by :- 1. Go to the directory of the project 2. Hold shift and right click and click on open command prompt here 3. Type mvn eclipse:eclipse if you want to build the project for eclipse IDE or mvn netbeans:netbeans if you want to build the project for netbeans 4. Close and open the project and your errors should be resolved

Upvotes: 0

The only thing I can think off is that LoginCheckAction source code is not being compilled properly or added to the war or EAR of your web application deployment.

Upvotes: 1

Sivakumar
Sivakumar

Reputation: 1751

Try without space <%@ page import="action.LoginCheckAction" %>

Upvotes: 0

Related Questions