我使用带有ejb的netbeans开发了一个简单的jsp登录页面。当我运行ejb-war时,问题就出现了。它显示一个正常的登录页面,当我点击提交时,它显示500内部服务器错误。请帮忙。
这是完整的错误
javax.servlet.ServletException: Error instantiating servlet class stateless.Mainpage
root cause
com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class stateless.Mainpage
root cause
com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=stateless.Mainpage/myuserFacade,Remote 3.x interface =stateless.MyuserFacadeRemote,ejb-link=null,lookup=,mappedName=,jndi-name=stateless.MyuserFacadeRemote,refType=Session into class stateless.Mainpage: Lookup failed for 'java:comp/env/stateless.Mainpage/myuserFacade' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
root cause
javax.naming.NamingException: Lookup failed for 'java:comp/env/stateless.Mainpage/myuserFacade' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=stateless.Mainpage/myuserFacade,Remote 3.x interface =stateless.MyuserFacadeRemote,ejb-link=null,lookup=,mappedName=,jndi-name=stateless.MyuserFacadeRemote,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'stateless.MyuserFacadeRemote#stateless.MyuserFacadeRemote' [Root exception is javax.naming.NamingException: Lookup failed for 'stateless.MyuserFacadeRemote#stateless.MyuserFacadeRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: stateless.MyuserFacadeRemote#stateless.MyuserFacadeRemote not found]]]
root cause
javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=stateless.Mainpage/myuserFacade,Remote 3.x interface =stateless.MyuserFacadeRemote,ejb-link=null,lookup=,mappedName=,jndi-name=stateless.MyuserFacadeRemote,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'stateless.MyuserFacadeRemote#stateless.MyuserFacadeRemote' [Root exception is javax.naming.NamingException: Lookup failed for 'stateless.MyuserFacadeRemote#stateless.MyuserFacadeRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: stateless.MyuserFacadeRemote#stateless.MyuserFacadeRemote not found]]
root cause
javax.naming.NamingException: Lookup failed for 'stateless.MyuserFacadeRemote#stateless.MyuserFacadeRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: stateless.MyuserFacadeRemote#stateless.MyuserFacadeRemote not found]
root cause
javax.naming.NameNotFoundException: stateless.MyuserFacadeRemote#stateless.MyuserFacadeRemote not found
我使用servlet将java代码连接到jsp页面,就像这样
@EJB
private MyuserFacadeRemote myuserFacade;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// request.
// String username = request.getParameter("username");
System.out.println("TESTTEST");
// System.out.println(username);
//String password = request.getParameter("password");
String res = myuserFacade.helloWorld();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
MyuserFacade代码
@Stateless
public class MyuserFacade implements MyuserFacadeRemote {
//EJBServer-ejbPU
@PersistenceContext(unitName = "EJBServer-ejbPU")
private EntityManager em;
protected EntityManager getEntityManager() {
return em;
}
public MyuserFacade() {
//super(Myuser.class);
}
public String helloWorld() {
return "Hello World";
}
@Override
public List<Myuser> getAllUsers() {
List<Myuser> userList = new ArrayList<Myuser>();
userList = em.createNamedQuery("Myuser.findAll").getResultList();
return userList;
}
@Override
public Myuser getUser(int userID) {
Myuser aUser = new Myuser();
aUser = (Myuser)em.createNamedQuery("Myuser.findByUserid").setParameter("userid", userID).getSingleResult();
return aUser;
}
@Override
public String deleteUser(int userID) {
Myuser aUser = getUser(userID);
em.remove(aUser);
return String.valueOf(userID);
}
@Override
public String createUser(int userid, String name, String password, String email, int tel, String address, String secqns, String secans) {
Myuser aUser = new Myuser();
aUser.setUserid(userid);
aUser.setName(name);
aUser.setPassword(password);
aUser.setEmail(email);
aUser.setTel(tel);
aUser.setAddress(address);
aUser.setSecqn(secqns);
aUser.setSecans(secans);
em.persist(aUser);
return String.valueOf(userid);
}
@Override
public String updateUser(int userid, String name) {
Myuser aUser = new Myuser();
aUser = (Myuser)em.createNamedQuery("Myuser.findByUserid").setParameter("userid", userid).getSingleResult();
aUser.setName(name);
em.persist(aUser);
return null;
}
@Override
public void updatePW(int userid, String newPW) {
Myuser aUser = new Myuser();
aUser = (Myuser)em.createNamedQuery("Myuser.findByUserid").setParameter("userid", userid).getSingleResult();
aUser.setPassword(newPW);
em.persist(aUser);
}
@Override
public Boolean verifyUser(String userName, String passWord) {
Myuser aUser = new Myuser();
aUser = (Myuser)em.createNamedQuery("Myuser.findByName").setParameter("name", userName).getSingleResult();
String uName = aUser.getName();
String uPass = aUser.getPassword();
if(userName.equals(uName)&&passWord.equals(uPass)){
return true;
}else{
return false;
}
}