我有一个简单的JEE应用程序,在登录时中断。在我把它从霓虹灯转移到火星之前它工作正常。虽然我将Server Runtime更改为WildFly 10.0,但它仍然说我的Server Runtime 10.x没有绑定(我改变了Web和EJB项目的运行时。无论如何,这是我的方法:
public String login(){
UserDto user = usersBean.validateUser(username, password);
if(null == user){
MessageUtils.addErrorMessage("login.error.invalid.credentials");
return "";
} else{
request.getSession().setAttribute("LOGGED_USER", user);
******the upper code fails********
return SUCCESS_LOGIN_REDIRECT;
}
}
堆栈追踪:
Context Path:/JEEProjectWeb
Servlet Path:/page/login.html
Path Info:null
Query String:null
Stack Trace
javax.servlet.ServletException: java.lang.NullPointerException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
bg.JEE.web.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:60)
io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
我对此非常新,并且不知道可能导致此错误的原因。但是我已经尝试将request.getSession()放在变量中,并且在调试时它返回null,所以setAttribute函数应该没有问题。
请帮助我!提前谢谢!
其他信息:
身份验证过滤器:
package bg.JEE.web.filter;
import java.io.IOException;
import java.io.Serializable;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import bg.JEE.dto.UserDto;
public class AuthenticationFilter implements Filter, Serializable {
private static final long serialVersionUID = 1L;
public static final String PATH_INDEX = "/index.jsp";
public static final String PATH_LOGIN = "/page/login.html";
public static final String PATH_LOGOUT = "/page/logout.jsp";
public void init(FilterConfig filterConfig) throws ServletException {
}
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestedPath = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length());
/*
* Skip the action with path "index.jsp" - there is no logged user, but
* the user is redirected to login screen
*/
if (PATH_INDEX.equals(requestedPath)) {
chain.doFilter(request, response); --row 60
return;
}
/*
* Skip the action with path "/login.login.html" - there is no logged
* user, but the user is trying to log in
*/
if (PATH_LOGIN.equals(requestedPath)) {
chain.doFilter(request, response);
return;
}
/*
* Get logged user from the HttpSession
*/
HttpSession session = httpRequest.getSession();
UserDto loggedUser = (UserDto) session.getAttribute("LOGGED_USER");
/*
* Redirect to login page if there is no logged user and trying to
* access protected resource
*/
if (loggedUser == null) {
RequestDispatcher requestDispatcher = request.getRequestDispatcher(PATH_LOGIN);
requestDispatcher.forward(request, response);
return;
} else {
chain.doFilter(request, response);
return;
}
}
}
这里是LoginBean的第60行代码:
public void setUsername(String username) {
this.username = username;
}
答案 0 :(得分:0)
似乎有几个问题。我无法帮助解决Eclipse问题,但另一个错误可能是问题的一部分。如果使用EJB,则需要使用beans.xml。它基本上可以是空的:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
如果您有Maven项目,请将其放在resources / META-INF / beans.xml中。如果您正在使用不同的构建系统,则此文件需要最终位于war文件/ webapp目录中的classes / META-INF / beans.xml中。
现在可以忽略另一个错误 - 节点标识符消息。如果您决定对Wildfly服务器进行群集,那么您需要对其进行更新 - 有关详情,请参阅this link。
但是为了更接近解决你的问题,请问&#34;请求&#34;传入?你能再展示一下你的代码了吗?