Struts 2 Hello World [英] Struts 2 Hello World

查看:55
本文介绍了Struts 2 Hello World的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此

web.xml代码:

 <?xml version ="1.0" encoding ="UTF-8"?>< web-app id ="WebApp_ID" version ="2.4" xmlns ="http://java.sun.com/xml/ns/j2ee" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation =" http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">< display-name> Hello World Struts 2</display-name>< welcome-file-list>< welcome-file> index.jsp</welcome-file></welcome-file-list><过滤器><过滤器名称> struts2</过滤器名称><过滤器类> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</过滤器类></filter><过滤器映射><过滤器名称> struts2</过滤器名称>< url-pattern>/*</url-pattern></filter-mapping></web-app> 

其他文件代码与struts网站相同.当我运行index.jsp文件时,出现以下错误:

** HTTP状态404-/helloworld/index.jsp

类型状态报告
消息/helloworld/index.jsp说明所请求的资源不可用.**

有人可以找出我无法运行的原因吗?

解决方案

首先,使用Maven配置创建项目,要访问Struts操作,应使用url

步骤6-构建WAR文件并运行应用程序

执行 mvn clean 包以创建war文件.

将war文件复制到您的Servlet容器中.在您的Servlet之后容器成功部署了war文件,请转到此URL http://localhost:8080/helloworld/index.action 您应该在哪里看到以下:


(来源: apache.org )

Web应用程序上下文是应用程序的部署位置.在文档url中为/helloworld ,在图像上为/Hello_World_Struts2_Ant .使用它作为URL的一部分.部署期间使用哪个应用程序上下文都无关紧要,但url取决于它.如果要更改Web应用程序上下文,则应阅读example

I work with eclipse for Java EE and Apache Tomcat 8. My project structure:

The web.xml code:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Hello World Struts 2</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>


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

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

</web-app>

The other files code is the same as the struts website. When I run the index.jsp file I get the following error:

**HTTP Status 404 - /helloworld/index.jsp

type Status report
message /helloworld/index.jsp description The requested resource is not available.**

Can someone spot the reason why can't I run it?

解决方案

First of all the project is created by using Maven configuration, and to access the Struts action you should use url

Step 6 - Build the WAR File and Run The Application

Execute mvn clean package to create the war file.

Copy the war file to your Servlet container. After your Servlet container successfully deploys the war file go to this URL http://localhost:8080/helloworld/index.action where you should see the following:


(source: apache.org)

Web application context is where the application was deployed. In the docs url it's /helloworld, on the image it's /Hello_World_Struts2_Ant. Use it as a part of the url. It doesn't matter which app context did you use during deployment but url depends on it. If you want to change the web app context you should read Java - How to change context root of a dynamic web project in Eclipse. After the context you use action name with .action extension to execute action.

Don't use URLs like localhost:8080/helloworld/index.jsp because you might not get the resource because it's already handled by the web server.

这篇关于Struts 2 Hello World的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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