简体   繁体   English

Struts2找不到jsp文件

[英]Struts2 doesn't find jsp files

I've been trying to no avail to set up a simple Struts2 application so I can get on with learning the framework. 我一直试图建立一个简单的Struts2应用程序,所以我可以继续学习框架。 Basically, what I am expecting to happen is that when an action is triggered that isn't defined, then a default page will be displayed. 基本上,我期望发生的是当触发未定义的动作时,将显示默认页面。

This app is being developed in Eclipse. 这个应用程序正在Eclipse中开发。

I have a very simple struts.xml file set up in the WEB-INF/classes directory: 我在WEB-INF / classes目录中设置了一个非常简单的struts.xml文件:

<struts>
<!-- Include webwork default (from the Struts JAR). -->
<include file="struts-default.xml" />

<!-- Configuration for the default package. -->

<package name="default" extends="struts-default">
    <action name="*">
        <result>/test.jsp</result>
    </action>
</package>
</struts>

I have the test.jsp file (just the default jsp template that gets created in Eclipse, ie "Insert title here") at the WebContent level, and the welcome page (which triggers the action) is index.jsp is also at that same level and gets displayed at program startup. 我有test.jsp文件(只是在Eclipse中创建的默认jsp模板,即“在此处插入标题”),WebContent级别,欢迎页面(触发操作)是index.jsp也是同样的级别并在程序启动时显示。 It is defined as follows: 它的定义如下:

 <%@page contentType="text/html" pageEncoding="UTF-8"%>
 <%@ taglib prefix="s" uri="/struts-tags" %>

<html>
  <head>
    <title>GlassFish JSP Page</title>
  </head>
<body>
<h1>Hello World!</h1>
<s:form action="other">
   <s:submit value="Submit" />
</s:form>
</body>
</html> 

I've also tried this with other action names, and no matter what, I get back a 404 page not found. 我也尝试过其他动作名称,无论如何,我都找不到404页面。 I've tried this on both GlassFish and Websphere 6.1.1 with the same results, leading me to suspect that there is something I am missing that is probably right in front of me involving either directory structure (are the paths relative to the struts.xml file or the context root?) or some configuration file. 我在GlassFish和Websphere 6.1.1上都尝试了相同的结果,这让我怀疑我遗漏的东西可能就在我面前涉及任一目录结构(相对于struts的路径)。 xml文件或上下文根?)或某些配置文件。

After some trying, I was able to get this up and running on Eclipse Ganymede on Mac OS X 10.5.6 using Glassfish, but I'm still having no luck with IBM Websphere and Application Server Toolkit (an Eclipse derivative) on Windows XP. 经过一番尝试,我能够使用Glassfish在Mac OS X 10.5.6上运行Eclipse Ganymede,但我仍然没有运行Windows XP上的IBM Websphere和Application Server Toolkit(Eclipse衍生产品)。 I am a bit suspicious that this might have something to do with the browser. 我有点怀疑这可能与浏览器有关。

I just tried adding a file called "other.action" to the same directory as my other JSP files mentioned above. 我只是尝试将一个名为“other.action”的文件添加到与上面提到的其他JSP文件相同的目录中。 Now when I click on the submit button that is linked to the "other" action, the action proceeds successfully to my test.jsp page. 现在,当我单击链接到“其他”操作的提交按钮时,操作将成功进入我的test.jsp页面。 I may be incorrect, but I don't believe that I should have to give a file named "someaction.action" for every possible "someaction" that I may need to use (I know I didn't need it on the OS X run of my app). 我可能是不正确的,但我不相信我应该为每个可能需要使用的“某些动作”提供名为“someaction.action”的文件(我知道我在OS X上不需要它)运行我的应用程序)。

More updates - I just tried it on Firefox 3.5.2 and running on that browser gave the same results - file not found without the "other.action" file on Websphere, so now I suspect it is a Websphere configuration issue. 更多更新 - 我刚刚在Firefox 3.5.2上尝试并在该浏览器上运行给出了相同的结果 - 在Websphere上没有找到“other.action”文件时找不到文件,所以现在我怀疑它是Websphere配置问题。

Using Firefox provided the key that I needed to determine the source of this issue - the Error 404: SRVE0190E message which told me that the problem was a Websphere configuration. 使用Firefox提供了确定此问题根源所需的密钥 - 错误404:SRVE0190E消息告诉我问题是Websphere配置。

The problem is explained in better detail at the following link: 在以下链接中更详细地解释了该问题:

IBM Websphere WebContainer throws a FileNotFoundException when a request is received for a static file which does not exist on the file system. 当收到文件系统上不存在的静态文件的请求时,IBM Websphere WebContainer会抛出FileNotFoundException。

And the solution is explained at this link (in this case, setting the com.ibm.ws.webcontainer.invokefilterscompatibility value=true): 并且在此链接中解释了解决方案(在这种情况下,设置com.ibm.ws.webcontainer.invokefilterscompatibility值= true):

Websphere setting up custom properties Websphere设置自定义属性

For completeness sake, I'll put how to correct this problem here: 为了完整起见,我将在这里提出如何纠正这个问题:

-In the administrative console, click "Servers" and under Servers click "Application Servers" - 在管理控制台中,单击“服务器”,然后在服务器下单击“应用程序服务器”

-Click on the server to which the custom property is to be applied - 单击要应用自定义属性的服务器

-Under "Configuration" and "Container settings" click "Web Container Settings" and under Web Container Settings click "Web Container" - 在“配置”和“容器设置”下单击“Web容器设置”,然后在“Web容器设置”下单击“Web容器”

-Under "Configuration" and "Additional Properties" click "Custom Properties" - 在“配置”和“其他属性”下单击“自定义属性”

-In the Custom Properties page, click "New" - 在“自定义属性”页面中,单击“新建”

-In the settings page, enter the name of the custom property to be added in the "Name" field and the value to be set for the custom property in the "Value" field. - 在设置页面中,在“名称”字段中输入要添加的自定义属性的名称,并在“值”字段中输入要为自定义属性设置的值。 Note that some properties are case sensitive. 请注意,某些属性区分大小写。 For this issue, the property is "com.ibm.ws.webcontainer.invokefilterscompatibility" and the value will be "true" 对于此问题,属性为“com.ibm.ws.webcontainer.invokefilterscompatibility”,值为“true”

-Click "Apply" or "OK" - 点击“应用”或“确定”

-Click "Save" in the "Messages" box that appears Restart the server for the custom property to take effect - 在出现的“消息”框中单击“保存”重新启动服务器以使定制属性生效

Are you definitely hitting the context root for your application. 你肯定是在为你的应用程序找到上下文根 ie in web.xml the application has a name this is normally the same as the context root unless you have packaged the application up into a war file with a different name. 即在web.xml ,应用程序的名称通常与上下文根相同,除非您已将应用程序打包到具有不同名称的war文件中。

http://yourserver:8080/yourcontextroot

I believe that Stuts 2 comes with some sample web applications and some maven archetypes. 我相信Stuts 2附带了一些示例Web应用程序和一些maven原型。 It's always a good idea to start with one of these and then customise it for your needs. 从其中一个开始,然后根据您的需求进行自定义始终是一个好主意。

http://struts.apache.org/2.1.2/docs/struts-maven-archetypes.html http://struts.apache.org/2.1.2/docs/struts-maven-archetypes.html

Struts 2 has an example project called struts-blank-2.x.xx.war . Struts 2有一个名为struts-blank-2.x.xx.war的示例项目。 http://mirrors.dedipower.com/ftp.apache.org/struts/examples/struts2-blank-2.0.14.war http://mirrors.dedipower.com/ftp.apache.org/struts/examples/struts2-blank-2.0.14.war

You can download it and rename it to .zip and see how they have set the project up. 您可以下载它并将其重命名为.zip ,看看他们如何设置项目。

WEB-INF/web.xml WEB-INF / web.xml文件

should have the struts2 servlet and filter 应该有struts2 servlet和filter

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

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

WEB-INF/classes/struts.xml should be in the classes folder and should point to your struts config file WEB-INF / classes / struts.xml应该在classes文件夹中,并且应该指向你的struts配置文件

    ...
    <include file="yourconfig.xml"/>

*WEB-INF/yourconfig.xml in the same folder as struts.xml and contains the mappings for your actions * WEB-INF / yourconfig.xmlstruts.xml位于同一文件夹中,包含操作的映射

...
<package name="example" namespace="/example" extends="struts-default">

    <action name="*" class="example.ExampleSupport">
        <result>/example/test.jsp</result>
    </action>

    <!-- Add actions here -->
</package>

All jsp files are in a folder called /example 所有jsp文件都在名为/example的文件夹中

I might be wrong, but for every action, it goes to /test.jsp. 我可能错了,但对于每一个动作,都会转到/test.jsp。 Yet you've just created [app name]/index.jsp?? 你刚刚创建了[app name] /index.jsp ?? Create a [app name]/test.jsp and point there!? 创建一个[app name] /test.jsp并指向那里!? (try removing the slash in the xml file before test.jsp?) (尝试在test.jsp之前删除xml文件中的斜杠?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM