我testBean就的Java EJB不注射
@Stateless
public class TestBean implements TestLocal {
public String getMessage(String name) {
return "Test "+ name;
}
}
我的界面
@Local
public interface TestLocal {
public String getMessage(String name);
}
在這裏,我用它
@EJB
private TestLocal testLocal;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String result;=testLocal.getMessage("ASDASD");
req.getSession().setAttribute("Test1",result);
RequestDispatcher rd=req.getRequestDispatcher("Index.jsp");
rd.forward(req,resp);
}
,我得到的結果行NullPointerException異常。
您應該在同一個EAR項目中擁有ejb和servlet。否則,請使用遠程訪問。 – Riadh