调用从JSP调用另一个Java方法的Java方法

时间:2014-11-18 16:53:37

标签: java jsp tomcat

所以我试图从LoginCheckAction.java调用LoginCheckAction.jsp中的Java方法。先前的方法调用LoginCheckBO.java中的方法,该方法是由LoginCheckBOImpl实现的接口。我收到了一个错误。

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);
    }

}

错误在LoginCheckAction.jsp中,我不明白为什么我收到该错误。有人可以解释一下吗?这是错误:

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)

0 个答案:

没有答案