0

So I am trying to call a Java method in LoginCheckAction.java from LoginCheckAction.jsp. The method in the prior calls a method in LoginCheckBO.java which is an interface implemented by LoginCheckBOImpl. I am getting an error.

LoginCheckAction.jsp

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

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

LoginCheckAction.java

package action;

import bo.LoginCheckBO;
import bo.impl.LoginCheckBOImpl;

public class LoginCheckAction{
    LoginCheckBO bo = new LoginCheckBOImpl();
    public LoginCheckAction(){
        super();
    }

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

LoginCheckBO.java

package bo;

public interface LoginCheckBO{

    public void printSomethingBO(String username);
}

LoginCheckBOImpl.java

package bo.impl;

import bo.LoginCheckBO;

public class LoginCheckBOImpl implements LoginCheckBO{

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

}

The error is in LoginCheckAction.jsp and I don't understand why I am getting that error. Can someone please explain? Here is the error:

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/LoginCheckAction.jsp at line 10

7: 
8:  LoginCheckAction ls = new LoginCheckAction();
9: //   ls.printSomething(username);
10:     ls.startBo(username);
11: %>


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause

java.lang.NullPointerException
    action.LoginCheckAction.startBo(LoginCheckAction.java:26)
    org.apache.jsp.jsp.LoginCheckAction_jsp._jspService(LoginCheckAction_jsp.java:65)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Obviously
  • 21
  • 2
  • 7
  • Stop using scriptlets. Use servlets as controller instead. – Luiggi Mendoza Nov 18 '14 at 16:55
  • I would have, but as you can see from this thread: [link](http://stackoverflow.com/questions/26994555/sending-post-data-from-jsp-to-a-java-servlet), it didn't workout. I fixed a lot of things since that post, and it's still not working out and I have no idea why. – Obviously Nov 18 '14 at 16:59
  • Well, we have no idea of the misconfigurations in that project (despite all the help we provided to you). Anyway, seems that most of your problems is due to a wrong compilation of your sources. From that *link* (your previous question), there's an image where the source code is not recognized as source folder for the application. Did you create the application from scratch and expected to magically work out of the box? – Luiggi Mendoza Nov 18 '14 at 17:02
  • One of my issues is that my classes were being built elsewhere, and I fixed that issue. Another problem was Tomcat not reading the WEB-INF folder because it was under a folder called WebContent. I fixed all these issues. I was at least able to call a method in a Java class using scriptlets. But I still can't figure out how to send post data to a servlet. Nothing I tried fixed it. You were able to see my directory, and it has changed a bit now. What do you suggest I can do? I am still learning. – Obviously Nov 18 '14 at 17:06
  • The compiled classes of the project go under WEB-INF/classes. Looks like the compiled classes aren't there. I would suggest to create a new Dynamic Web project in Eclipse and move the elements in your current project to that new project. After moving and do your basic testing, then [stop using scriptlets at all](http://stackoverflow.com/questions/3177733/howto-avoid-java-code-in-jsp-files) and go back to the Servlet approach. – Luiggi Mendoza Nov 18 '14 at 17:08
  • I already did that. Here is a screenshot of my new directory. http://imgur.com/c1awPWk – Obviously Nov 18 '14 at 17:12
  • Ugh... Please go to the Project Explorer view, from the menu on top, Window/Show View/Project Explorer. Then, search for your project and provide the image one more time. – Luiggi Mendoza Nov 18 '14 at 17:15
  • Sorry it took me some time, I was driving home. Here is a screenshot of the Project Explorer view: http://imgur.com/xP5ggQF – Obviously Nov 18 '14 at 18:10
  • Everything seems fine. Try to compile the project and redeploy it. If you're using tomcat then it would be better to deploy it directly into tomcat deploy folder rather than in the automatic folder eclipse creates for you. [Here](http://stackoverflow.com/q/3515089/1065197) is an explanation on how to do it. – Luiggi Mendoza Nov 18 '14 at 19:01

0 Answers0