0

このようなエラーが発生します。これは、プログラムを実行したときに発生し、実行されませんでした。次のエラーが表示されました。

Jul 10, 2013 1:21:24 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Kaspersky Lab\Kaspersky Anti-Virus 6.0 for Windows Workstations MP4\;C:\Program Files\Java\jdk1.6.0_07/bin;C:\Program Files\MySQL\MySQL Server 5.2\bin;D:\common libs\com.mysql.jdbc_5.1.5.jar;;C:\Users\lcladmin\Documents\Softwares\java related\eclipse-jee-indigo-win32_2\eclipse;
Jul 10, 2013 1:21:24 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:BankDemoWeb' did not find a matching property.
Jul 10, 2013 1:21:24 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jul 10, 2013 1:21:24 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jul 10, 2013 1:21:24 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 552 ms
Jul 10, 2013 1:21:24 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 10, 2013 1:21:24 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.41
Jul 10, 2013 1:21:25 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter FilterRequest
java.lang.ClassCastException: com.mobitel.bankdemo.web.FilterRequest cannot be cast to javax.servlet.Filter
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4746)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5399)
    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$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Jul 10, 2013 1:21:25 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error filterStart
Jul 10, 2013 1:21:25 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/BankDemoWeb] startup failed due to previous errors
Jul 10, 2013 1:21:25 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 10, 2013 1:21:25 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 10, 2013 1:21:25 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 533 ms

このエラーが発生する理由を教えてもらえますか? (jsp、servlet、tomcatを使用してWeb Javaアプリケーションを実行しています。)

ここに私の FilterRequest.java ファイルコード

package com.mobitel.bankdemo.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.logging.Filter;
import java.util.logging.LogRecord;
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.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mobitel.bankdemo.domain.User;

public class FilterRequest implements Filter{
    private static final long serialVersionUID = 1L;
    FilterConfig filterConfig = null;
    public FilterRequest() {
        super();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {       
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
            HttpServletRequest request = (HttpServletRequest) req;
            HttpServletResponse response = (HttpServletResponse) resp;
                      HttpSession session = request.getSession(true);
          User u = (User) session.getAttribute("loggedUser");
          System.out.println(u+"i");
          if (u!= null)
          {
             System.out.println(u+"u");
             chain.doFilter(req, resp);
             return;
          }else{
              String message = "Please Login!";             
              req.setAttribute("loginMsg", message);
              response.sendRedirect("login2.jsp");
          }             
    }
    public void destroy() {
        // do cleanup stuff
    }
    @Override
    public boolean isLoggable(LogRecord arg0) {
        // TODO Auto-generated method stub
        return false;
    }
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>BankDemoWeb</display-name>
  <welcome-file-list>
    <welcome-file>home.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>AccountController</servlet-name>
    <servlet-class>com.mobitel.bankdemo.web.AccountControllerServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>AccountController</servlet-name>
    <url-pattern>/account</url-pattern>
  </servlet-mapping>

  <session-config>
    <session-timeout>5</session-timeout>
  </session-config>

   <filter>
        <filter-name>FilterRequest</filter-name>
        <filter-class>com.mobitel.bankdemo.web.FilterRequest</filter-class>             
  </filter>
  <filter-mapping>
        <filter-name>FilterRequest</filter-name>
        <url-pattern>/*</url-pattern>
  </filter-mapping> 

4

2 に答える 2

3

ここでは、次のようにimplementsフィルターします。

public class FilterRequest implements Filter

しかし、あなたが期待したものではありません。あなたのインポートを見てください:

import java.util.logging.Filter;

次のものに置き換える必要があります。

import javax.servlet.Filter

次に、ユーザーがすでにアクセスしようとしている場合は、ユーザーをログインページにリダイレクトしないでください (そうしないと、フィルターで無限ループが発生します)。

これを置き換える必要がありますif statement

if (u!= null)

と:

if (u!= null || request.getServletPath().equals("/login2.jsp"))
于 2013-07-10T09:11:25.537 に答える