资源不可用错误使用Eclipse Kepler与Struts 2 + Tomcat 7 [英] Resource not available error using Eclipse Kepler with Struts 2 + Tomcat 7

查看:184
本文介绍了资源不可用错误使用Eclipse Kepler与Struts 2 + Tomcat 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以这是我的第一个使用Java编写的应用程序,我第一次使用Eclipse Kepler,Tomcat 7和Struts2,所以我很惊讶,我甚至有这么远,因为我知道的只有JS和Rails。无论如何,这个基本的Web应用程序字面上只是在运行Tomcat 7时在IDE中输入该URL时输出字符串Success Page!



我查看了Tomcat的成功页面,所以我知道运行时服务器正在运行。另外,我的IDE中没有红色的x标记。该教程告诉我添加到我完成的网络应用程序的URL getTutorial.action ,以便呈现 success.jsp 视图。



但是,我在url localhost上收到此错误:8080 / Struts2Starter / getTutorial.action

 消息/Struts2Starter/getTutorial.action 

描述请求的资源不可用。

错误日志告诉我:

  SEVERE:调度程序初始化失败
无法加载配置。 - action - file:/Users/jasonrodriguez/Java/apache-tomcat-7.0.47/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:76

SEVERE:调度程序初始化失败
无法加载配置。 - action - file:/Users/jasonrodriguez/Java/apache-tomcat-7.0.47/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:76
at com.opensymphony.xwork2.config。 ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
在org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
在org.apache.struts2.dispatcher.Dispatcher.init( Dispatcher.java:490)
在org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
在org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter。 init(StrutsPrepareAndExecuteFilter.java:57)
在org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
在org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig。 java:262)
在org.apache.catalina.core.ApplicationFilterConfig。< init>(ApplicationFilterConfig.java:107)
在org.apache.catalina.core.Standa rdContext.filterStart(StandardContext.java:4775)
在org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
在org.apache.catalina.util.LifecycleBase.start( LifecycleBase.java:150)
在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559)
在org.apache.catalina.core.ContainerBase $ StartChild.call( ContainerBase.java:1549)
在java.util.concurrent.FutureTask.run(FutureTask.java:262)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)
在java.lang.Thread.run(Thread.java:744)
引起的:Action class [没有找到org.koushik.javabrains.TutorialAction - action - file:/Users/jasonrodriguez/Java/apache-tomcat-7.0.47/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:76
在com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAct ion(XmlConfigurationProvider.java:482)
在com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:426)
在com.opensymphony.xwork2.config.providers.XmlConfigurationProvider。 addPackage(XmlConfigurationProvider.java:552)
在com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:292)
在org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages( strutsXmlConfigurationProvider.java:112)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:250)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager。 java:67)
... 16更多

SEVERE:错误filterStart

我的web.xml:

 <?xml version =1.0encoding =UTF-8? > 
< web-app xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexmlns =http://java.sun.com/xml/ns/javaeexsi :schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsdid =WebApp_IDversion =3.0 >
< display-name> Struts2Starter< / display-name>
< welcome-file-list>
< welcome-file> index.html< / welcome-file>
< welcome-file> index.htm< / welcome-file>
< welcome-file> index.jsp< / welcome-file>
< welcome-file> default.html< / welcome-file>
< welcome-file> default.htm< / welcome-file>
< welcome-file> default.jsp< / welcome-file>
< / welcome-file-list>

< filter>
< filter-name> struts2< / filter-name>
< filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter< / filter-class>
< / filter>

< filter-mapping>
< filter-name> struts2< / filter-name>
< url-pattern> / *< / url-pattern>
< / filter-mapping>

< / web-app>

我的struts.xml:

 <?xml version =1.0encoding =UTF-8?> 
<!DOCTYPE struts PUBLIC
- // Apache Software Foundation // DTD Struts Configuration 2.0 // EN
http://struts.apache.org/dtds/struts- 2.0.dtd>

< struts>

< package name =defaultextends =struts-default>

< action name =getTutorialclass =org.koushik.javabrains.TutorialAction>
< result name =success> /success.jsp< / result>
< result name =failure> /error.jsp< / result>
< / action>

< / package>

< / struts>

我的TutorialAction.java:

  package org.koushik.javabrains.action; 

public class TutorialAction {

public String execute(){
System.out.println(Hello from execute);
returnsuccess;
}
}

我的success.jsp视图:

 <%@ page language =javacontentType =text / html; charset = US-ASCII
pageEncoding =US -ascii%>
<!DOCTYPE html PUBLIC - // W3C // DTD HTML 4.01 Transitional // ENhttp://www.w3.org/TR/html4/loose.dtd\">
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = US-ASCII>
< title>在此插入标题< / title>
< / head>
< body>
成功页!
< / body>
< / html>

我正在努力解决这个问题。在Rails中,我会抛出一个 binding.pry ,但这里我不是一丝不苟的问题。最好我可以告诉,路由可能在某个地方搞砸了。任何洞察力都将是非常有帮助的感谢!!

解决方案

当struts2应用程序引导它从 struts加载配置.XML 。它解析该文档并创建配置相关对象并将其放入内部容器中。然后使用这个配置对象来实例化动作,结果,拦截器等真实的对象。在应用程序中存在的配置中指定类很重要。 Eclipse只能编译Java文件,甚至验证 struts.xml 的DTD,但不能解决配置错误。 Struts2在引导时执行。因此,您得到的动作类不能解析的错误。要修复错误,您应该提供类路径中存在的类引用。

 < action name =getTutorialclass =org.koushik.javabrains.action.TutorialAction> 
< result> /success.jsp< / result>
< result name =failure> /error.jsp< / result>
< / action>

注意,结果名称success是结果的默认名称,可以省略。


Ok, so this is my first app written in Java and my first time using Eclipse Kepler, Tomcat 7, and Struts2 so I am surprised that I even got this far since all I know is JS and Rails. Anyway, this basic web app literally is just supposed to output the string "Success Page!" when you enter that URL in the IDE while running Tomcat 7.

I viewed the Tomcat success page so I know the runtime server is working. Also, I am getting no red x marks in my IDE. The tutorial told me to add to the URL getTutorial.action of my completed web app in order to render the success.jsp view.

However, I get this error at the url localhost:8080/Struts2Starter/getTutorial.action:

message /Struts2Starter/getTutorial.action

description The requested resource is not available.

The error log tells me this :

    SEVERE: Dispatcher initialization failed
    Unable to load configuration. - action - file:/Users/jasonrodriguez/Java/apache-tomcat-7.0.47/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:76

SEVERE: Dispatcher initialization failed
Unable to load configuration. - action - file:/Users/jasonrodriguez/Java/apache-tomcat-7.0.47/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:76
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
    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.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: Action class [org.koushik.javabrains.TutorialAction] not found - action - file:/Users/jasonrodriguez/Java/apache-tomcat-7.0.47/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:76
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:482)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:426)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:552)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:292)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:250)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
    ... 16 more

SEVERE: Error filterStart

My 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" 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>Struts2Starter</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>

My struts.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <package name="default" extends="struts-default">

        <action name="getTutorial" class="org.koushik.javabrains.TutorialAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/error.jsp</result>
        </action>

    </package>

</struts>

My TutorialAction.java :

package org.koushik.javabrains.action;

public class TutorialAction {

    public String execute() {
        System.out.println("Hello from execute");
        return"success";
    }
}

My success.jsp view :

<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Insert title here</title>
</head>
<body>
    Success Page!
</body>
</html>

I am struggling to troubleshoot this. In Rails I'd throw in a binding.pry but here I am not the slightest clue how to troubleshoot. Best I can tell, perhaps the routing got messed up somewhere. Any insight would be really helpful thanks!!

解决方案

When struts2 app bootstraps it load the configuration from struts.xml. It parses that document and create config related objects and put them into the internal container. Then used this config objects to instantiate real objects like actions, results, interceptors, etc. It's important to specify classes in the configuration that exist in the application. Eclipse can only compile a Java files and even validate DTD of struts.xml but it will not resolve configuration errors. Struts2 is doing it on bootstrap. As a result you got the error that action class is not resolvable. To fix the error you should provide the class reference that exist on the classpath.

<action name="getTutorial" class="org.koushik.javabrains.action.TutorialAction">
    <result>/success.jsp</result>
    <result name="failure">/error.jsp</result>
</action>

Note, the result name "success" is the default name of the result and could be omitted.

这篇关于资源不可用错误使用Eclipse Kepler与Struts 2 + Tomcat 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆