-3

我在尝试从 web.xml 调用 java 类时遇到问题,当我运行我的应用程序时,我无法加载我的类/方法?

在我的应用程序中:
jsf 2.0
primefaces 3.1.1
springframework 3.0.2

请帮我

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/app-config.xml</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>

<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/app-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>Mama</servlet-name>
    <servlet-class>hobic.controller.Mama</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Mama</servlet-name>
    <url-pattern>/hobic.controller</url-pattern>
</servlet-mapping>


</web-app>

妈妈.java

public class Mama extends HttpServlet{

public Mama() {
    super();
}

public void metalica() {
    System.out.println("nothing else matter");
    JOptionPane.showMessageDialog(null, "nothing else matter");
}
}

错误

SEVERE: Exception while visiting CryptoMeWindow$1.class of size 122769
java.lang.ArrayIndexOutOfBoundsException: 130207
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.glassfish.hk2.classmodel.reflect.Parser$5.on(Parser.java:362)
    at com.sun.enterprise.v3.server.ReadableArchiveScannerAdapter.handleEntry(ReadableArchiveScannerAdapter.java:171)
    at com.sun.enterprise.v3.server.ReadableArchiveScannerAdapter.onSelectedEntries(ReadableArchiveScannerAdapter.java:133)
    at org.glassfish.hk2.classmodel.reflect.Parser.doJob(Parser.java:348)
    at org.glassfish.hk2.classmodel.reflect.Parser.access$300(Parser.java:70)
    at org.glassfish.hk2.classmodel.reflect.Parser$3.call(Parser.java:307)
    at org.glassfish.hk2.classmodel.reflect.Parser$3.call(Parser.java:296)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

INFO: SEC1002: Security Manager is OFF.
INFO: SEC1010: Entering Security Startup Service
INFO: SEC1143: Loading policy provider    com.sun.enterprise.security.provider.PolicyWrapper.
INFO: SEC1115: Realm [admin-realm] of classtype  [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
INFO: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
INFO: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
INFO: SEC1011: Security Service(s) Started Successfully
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: WEB0169: Created HTTP listener [http-listener-1] on host/port [0.0.0.0:8080]
INFO: WEB0169: Created HTTP listener [http-listener-2] on host/port [0.0.0.0:8181]
INFO: WEB0169: Created HTTP listener [admin-listener] on host/port [0.0.0.0:4848]
INFO: WEB0171: Created virtual server [server]
INFO: WEB0171: Created virtual server [__asadmin]
INFO: WEB0172: Virtual server [server] loaded default web module []
INFO: JTS5014: Recoverable JTS instance, serverId = [3700]
INFO: Portable JNDI names for EJB TestSessionBean : [java:global/Hobic/Hobic-   ejb/TestSessionBean!hobic.view.TestSessionBeanRemote, java:global/Hobic/Hobic- ejb/TestSessionBean]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB TestSessionBean :   [hobic.view.TestSessionBeanRemote#hobic.view.TestSessionBeanRemote,  hobic.view.TestSessionBeanRemote]
INFO: Initializing Mojarra 2.1.3 (FCS b02) for context '/Hobic-war'
INFO: Instantiated an instance of  org.hibernate.validator.engine.resolver.JPATraversableResolver.
WARNING: JSF1074: Managed bean named 'loginBean' has already been registered.     Replacing existing managed bean class type hobic.controller.LoginBean with  hobic.controller.LoginBean.
INFO: Running on PrimeFaces 3.1.1
INFO: PWC1412: WebModule[null] ServletContext.log():Initializing Spring root  WebApplicationContext
SEVERE: log4j:WARN No appenders could be found for logger  (org.springframework.web.context.ContextLoader).
SEVERE: log4j:WARN Please initialize the log4j system properly.
SEVERE: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more  info.
INFO: Instantiated an instance of  org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: PWC1412: WebModule[null] ServletContext.log():Initializing Spring FrameworkServlet 'Spring MVC Dispatcher Servlet'
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: WEB0671: Loading application [Hobic#Hobic-war.war] at [Hobic-war]
INFO: Hobic was successfully deployed in 45,269 milliseconds.
4

3 回答 3

2

你的 web.xml 说

<servlet>
    <servlet-name>Mama</servlet-name>
    <servlet-class>hobic.controller.Mama</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Mama</servlet-name>
    <url-pattern>/hobic.controller</url-pattern>
</servlet-mapping>

实际上,您的Mama课程只是一个普通的 POJO,其中Swing嵌入了一些代码。

为了让 Mama 成为一个Servlet,它应该扩展 HttpServlet,并覆盖其中一个服务方法。

另外请删除所有 Swing 代码MamaSwing用于 UI 目的的独立 Java 应用程序,它在 Web 应用程序中对于驻留在服务器上的代码也没有任何价值。

所以你Mama应该看起来像这样:

public class Mama extends HttpServlet {

   // override service method(s) that you intend to support.

}

在此处阅读基本教程

于 2012-05-28T04:22:55.357 回答
0

在 web.xml 中,您只能指定扩展 HttpServlet 的 servlet 类。我们不能在 servlet 类中摆动代码。所以请删除摇摆代码。

于 2012-05-28T04:22:06.947 回答
0

您在应用程序中使用了错误的配置样式。请查看这些链接http://www.mkyong.com/jsf2/jsf-2-0-spring-integration-example/,这可能对您有所帮助。请不要在 Web 应用程序中使用 swing 代码,并且在扩展 HttpServlet 时必须编写 doGet() 或 doPost() 方法。

于 2012-05-28T10:24:04.793 回答