【发布时间】:2013-11-29 13:54:03
【问题描述】:
好的,这是我第一个用 Java 编写的应用程序,也是我第一次使用 Eclipse Kepler、Tomcat 7 和 Struts2,所以我很惊讶我能走到这一步,因为我只知道 JS 和 Rails。无论如何,当您在运行 Tomcat 7 时在 IDE 中输入该 URL 时,这个基本的 Web 应用程序实际上应该输出字符串 "Success Page!"。
我查看了 Tomcat 成功页面,因此我知道运行时服务器正在运行。此外,我的 IDE 中没有红色 x 标记。该教程告诉我添加到我已完成的 Web 应用程序的 URL getTutorial.action 以呈现 success.jsp 视图。
但是,我在 url localhost:8080/Struts2Starter/getTutorial.action 处收到此错误:
message /Struts2Starter/getTutorial.action
description The requested resource is not available.
错误日志告诉我:
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
我的 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>
我的 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>
我的 TutorialAction.java :
package org.koushik.javabrains.action;
public class TutorialAction {
public String execute() {
System.out.println("Hello from execute");
return"success";
}
}
我的success.jsp视图:
<%@ 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>
我正在努力解决这个问题。在 Rails 中,我会输入binding.pry,但在这里我一点也不知道如何进行故障排除。我能说的最好的,也许路由在某个地方搞砸了。任何见解都会非常有帮助,谢谢!
【问题讨论】:
-
你了解包的概念吗?错误消息告诉的是找不到动作类 TutorialAction。我可以看到有一些包声明。 java 类应位于以下目录结构中。 org/koushik/javabrains/actions/TutorialAction.java
-
这会导致您的 FilterDispatcher 初始化失败。
-
感谢您的帮助。我不知道什么是包。我只是按照教程进行操作,但我可以猜到,一个包是否类似于 Ruby Gem?
标签: java eclipse tomcat configuration struts2