如何在 Eclipse Galileo 中创建 Struts 2 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2304546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:25:49  来源:igfitidea点击:

How to create Struts 2 project in Eclipse Galileo?

javaeclipsestruts2

提问by Anand

I want to create a struts 2 project in eclipse. I have downloaded the latest struts distribution. But things always become confusing when i try to create a struts project in ECLIPSE. Whenever I create a dynamic web project and add struts libraries to that project, some error or the other pops up.

我想在 Eclipse 中创建一个 struts 2 项目。我已经下载了最新的 struts 发行版。但是当我尝试在 ECLIPSE 中创建一个 struts 项目时,事情总是变得混乱。每当我创建一个动态 Web 项目并将 struts 库添加到该项目时,就会出现一些错误或其他错误。

How do I properly setup an eclipse Struts 2 project ?

如何正确设置 Eclipse Struts 2 项目?

To get a simple Hello world page, I did:

为了得到一个简单的 Hello world 页面,我做了:

  1. created a dynamic web project (procollab)
  2. added struts 2 jars inside WEB-INF/lib
  3. added the same libraries inside project build path
  4. set the output folder for the src in WEB-INF/classes
  5. created a filter in web.xml to send all requests to org.apache.struts2.dispatcher.FilterDispatcher
  6. created a struts.xml in src
  1. 创建了一个动态网络项目(procollab)
  2. 在 WEB-INF/lib 中添加了 struts 2 jars
  3. 在项目构建路径中添加了相同的库
  4. 在 WEB-INF/classes 中为 src 设置输出文件夹
  5. 在 web.xml 中创建了一个过滤器,将所有请求发送到 org.apache.struts2.dispatcher.FilterDispatcher
  6. 在 src 中创建了一个 struts.xml

Errors I get:

我得到的错误:

Http 404. I get this for any URL, for example http://localhost:8080or http://localhost:8080/procollab

Http 404。我为任何 URL 获取此信息,例如 http://localhost:8080http://localhost:8080/procollab

I have added the project procollab in tomcat server list also in eclipse. but when I access any static resource directly, I get the page. I have the helloworld.jsp in webcontent folder, and when I go to http:localhost:8080/procollab/helloworld.jsp, I get the page correctly.

我也在 eclipse 中在 tomcat 服务器列表中添加了项目 procollab。但是当我直接访问任何静态资源时,我得到了页面。我在 webcontent 文件夹中有 helloworld.jsp,当我转到 http:localhost:8080/procollab/helloworld.jsp 时,我得到了正确的页面。

Have I set up my environment correctly ? Please help

我是否正确设置了环境?请帮忙

my struts.xml file in WEB-INF/classes

我的 WEB-INF/classes 中的 struts.xml 文件

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

<struts>
    <package name="default" namespace="/" extends="struts-default">
        <action name="SayHello">
            <result>/hello.jsp</result>
        </action>

    </package>

</struts>

采纳答案by BalusC

Http 404. I get this for any URL, for example http://localhost:8080or http://localhost:8080/procollab

Http 404。我为任何 URL 获取此信息,例如http://localhost:8080http://localhost:8080/procollab

So that's the only problem? Well, a 404 just means that there's no resource on the requested URL. Page Not Found. Simple as that. You need to provide/specify the resource yourself, Eclipse won't do that for you or so. It's the code which you have full in control yourself.

所以这是唯一的问题吗?好吧,404 只是意味着请求的 URL 上没有资源。找不到网页。就那么简单。您需要自己提供/指定资源,Eclipse 不会为您做这些。这是您可以完全控制自己的代码。

I am not sure what you expect to see at http://localhost:8080, so I'll ignore this part. As to the 404 on http://localhost:8080/procollab, you just need to define a <welcome-file>in the web.xmland ensure that this is available by either (in)directly by a servlet or filter mapping, or a physical file in WebContent. That's all.

我不确定您希望在http://localhost:8080看到什么,所以我将忽略这部分。至于404上的http://本地主机:8080 / procollab,你只需要定义一个<welcome-file>web.xml直接通过servlet或过滤器映射,或者在一个物理文件,并确保这是可通过(中)WebContent。就这样。

If you want to make helloworld.jspthe default landing page, you'll need to add the following to the web.xml:

如果要制作helloworld.jsp默认登录页面,则需要将以下内容添加到web.xml

<welcome-file-list>
    <welcome-file>/helloworld.jsp</welcome-file>
</welcome-file-list>

Update: as per the posted struts config, you thus expect that http://localhost:8080/procollab/SayHello.actionis been executed when you access http://localhost:8080/procollab. In this case, you need to configure the <welcome-file>as follows:

更新:根据发布的 struts 配置,您因此期望在访问http://localhost:8080/procollab时执行http://localhost:8080/procollab/SayHello.action。在这种情况下,您需要进行如下配置:<welcome-file>

<welcome-file-list>
    <welcome-file>/SayHello.action</welcome-file>
</welcome-file-list>