Using Struts2 from scratch

本文详细介绍了如何使用Struts2框架搭建一个基本的Java Web应用,包括下载Struts2.3.4版本、配置项目环境、添加依赖及过滤器、创建配置文件struts.xml等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Official Website

    http://struts.apache.org/


    Click struts2.3.4(GA) in Documentation
    Click download now
    * Version Notes (包含下面 4 个文件)
    * Full Distribution:
          o struts-2.3.4-all.zip (76mb) [PGP ] [MD5 ]
    * Example Applications:
          o struts-2.3.4-apps.zip (29mb) [PGP ] [MD5 ]
    * Essential Dependencies Only:
          o struts-2.3.4-lib.zip (15mb) [PGP ] [MD5 ]
    * Documentation:
          o struts-2.3.4-docs.zip (33mb) [PGP ] [MD5 ]
    * Source:
          o struts-2.3.4-src.zip (6mb) [PGP ] [MD5 ]


2. 包结构


3. 创建第一个项目

    http://struts.apache.org/2.x/docs/create-struts-2-web-application-with-artifacts-in-web-inf-lib-and-use-ant-to-build-the-application.html

 

Official Seven Steps:

Step 1 - Create A Basic Java Web Application

Step 2 - Add index.jsp and Ant Build File

Step 3 - Add Struts 2 Jar Files To Class Path

Step 4 - Add Logging

Step 5 - Add Struts 2 Servlet Filter

Step 6 - Create struts.xml

Step 7 - Build and Run the Application

 

   a. copy struts-2.2.1\apps\struts2-blank-2.2.1\WEB-INF\lib to /Basic_Struts2_Ant/WebContent/WEB-INF/lib

   b. add filter to web.xml

 

<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>

   c. Create 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>

	<constant name="struts.devMode" value="true" />

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

		<action name="index">
			<result>/index.jsp</result>
		</action>

	</package>

</struts>

    d. Add Jsp

    e. deploy to tomcat and run the application

    f. open http://localhost:8080/Basic_Struts2_Ant/index.action successful.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值