8

ここで何が問題なのかわからないので、助けてください。これは例外です:

SEVERE: Exception starting filter com.bannerplay.beans.LoginFilter
java.lang.IllegalAccessException: Class org.apache.catalina.core.DefaultInstanceManager can not access a member of class com.bannerplay.beans.LoginFilter with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:134)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:256)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

login.xhtml

<h:form>
    Username : <h:inputText value="#{loginBean.username}" />
    Password : <h:inputSecret value="#{loginBean.password}" />
<h:commandButton value="Login" action="#{loginBean.checkLogin}" />
</h:form>

web.xml

  <filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.bannerplay.beans.LoginFilter</filter-class>
  </filter>
  <filter-mapping>
<filter-name>LoginFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/admin/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
     <welcome-file>/login.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
       <servlet-name>FacesServlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
  </servlet>
  ...

および LoginFilter.java

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@WebFilter("/admin/*")
class LoginFilter implements Filter {
@Override
public void doFilter(ServletRequest request , ServletResponse response , FilterChain chain) throws ServletException, IOException {
    HttpSession session = ((HttpServletRequest) request).getSession();
    UserBean userBean = (UserBean) session.getAttribute("userBean");
    if (userBean != null) {
        User user = userBean.getUser();
        if (user == null) {
            ((HttpServletResponse) response).sendRedirect("/login.xhtml");
        } else
            chain.doFilter(request, response);
    } else
        ((HttpServletResponse) response).sendRedirect("/login.xhtml");
}

public void init(FilterConfig fc) {
}

public void destroy() {
}
}

この例外がどこから来たのかわかりません。この問題に光を当ててください。ありがとう!

EDIT1 : UserBean.java コードの追加:

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
class UserBean implements Serializable {
/**
 * 
 */
private static final long serialVersionUID = 1L;

public User getUser() {
    return user;
}

public void setUser(User user) {
    this.user = user;
}

private User user;
}

ところで、重大: コンテキスト [/projectName] の起動は、以前のエラーが原因で失敗しました

4

2 に答える 2

14

変化 :

class LoginFilter implements Filter {

public class LoginFilter implements Filter {

于 2012-09-24T15:03:53.013 に答える
5

私にとっての問題は、「コンストラクター」が存在しないことpublicでした。

于 2014-11-04T12:16:04.273 に答える