• 下载的struts2xx-all.zip包对搭建项目的作用

一般情况下,我们下载一个Struts2的full包时,并不知道新建过程中需要哪些包,那么这时我们可以从下载的包中解压出的目录\apps\struts2-blank.war文件找解决方案。

我从http://struts.apache.org/下载的是struts-2.3.28-all.zip包,解压到本地后目录结构如下:

apps目录下包含文件及作用:

struts2-blank.war 它可以告诉你如何搭建一个最最简单的Struts2的项目;它还会告诉你,Struts2至少需要依赖哪些jar包(请以后不要再为jar包错误而苦恼);同时,也给你做出了一些范例,web.xml怎么写,struts.xml又怎么写。

struts2-mailreader.war 给出了注册流程、以及发邮件功能

struts2-portlet.war 则给出了在Portal环境下的Struts2的应用。

struts2-rest-showcase.war 讲述了Restful的用法示例。

struts2-showcase.war 这个项目,你则可以看到Struts2的特性的大杂烩,这对于你看reference是相当有帮助的。比如说,你在看文档时看到了"文件上传"的章节,那么你就可以参考项目中的upload子目录。

怎么使用:

1.可以把这些文件拷贝到tomcat的webapps下,之后访问:http://localhost:8080/struts2-blank,之后去webapps下可以查看具体的发布文件夹;

2.也可以当做压缩包来解压出具体的发布文件夹。

  • 以下将会介绍怎么新建一个struts2的工程:

1、使用eclipse创建一个Dynamic web project.

2、添加struts2需要的jar包。

将struts2-blank.war解压后\struts2-blank\WEB-INF\lib下jar包,拷贝到工程\WebContent\WEB-INF\lib文件夹下。

3、修改web.xml

将struts2-blank.war解压后\WEB-INF\web.xml拷贝到新建工程MyStruts001的\WebContent\WEB-INF\web.xml中,并修改为:

 <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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>Struts Blank</display-name> <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> <welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list> <!-- Restricts access to pure JSP files - access available only via Struts action -->
<!--<security-constraint>
<display-name>No direct JSP access</display-name>
<web-resource-collection>
<web-resource-name>No-JSP</web-resource-name>
<url-pattern>*.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>no-users</role-name>
</auth-constraint>
</security-constraint> <security-role>
<description>Don't assign users to this role</description>
<role-name>no-users</role-name>
</security-role>
-->
</web-app>

3、新建struts.xml相关文件到Src下。

把struts-blank\WEB-INF\src\java\下的struts.xml,log4j2.xml,velocity.properties拷贝到MyStruts001的\src下。

4、新建一个struts2的Action类。

5、修改struts.xml文件如下:

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<constant name="struts.action.extension" value="action" />
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" /> <package name="default" namespace="/MyStruts001" extends="struts-default">
<default-action-ref name="index" />
<global-results>
<result name="error">/WEB-INF/pages/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception"
result="error" />
</global-exception-mappings>
<action name="project-info">
<result>/WEB-INF/pages/input.jsp</result>
</action>
<action name="product-save" class="com.dx.struts001.actions.ProjectAction">
<result name="detail">/WEB-INF/pages/result.jsp</result>
</action>
</package>
</struts>

6、新建相关view页面。

default.html

 <!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="project-info.action"> hellword.action </a>
</body>
</html>

WEB-INF/pages/input.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="product-save.action" method="POST">
<label>name:</label>
<input type="text" name="name" />
<br />
<input type="submit" name="submit" />
</form>
</body>
</html>

WEB-INF/pages/result.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body> </body>
</html>

7、运行项目,之后访问地址:http://localhost:8080/MyStruts001/

界面为:

点击"helloword.action",界面为:

输入信息,点击“提交”按钮.

到此结束。

Struts2(三):新建Struts2工程的更多相关文章

  1. 【Struts2】新建一个Struts2工程,初步体验MVC

    实现目标 地址栏输入http://localhost:88/Struts2HelloWorld/helloworld.jsp 输入用户名,交由http://localhost:88/Struts2He ...

  2. struts2学习笔记(三)—— struts2的常见配置

    一.配置文件的加载顺序 每次从客户端发送请求到服务器都要先经过Struts2的核心过滤器StrutsPrepareAndExecuteFilter,这个过滤器有两个功能:预处理和执行.在预处理中主要就 ...

  3. struts2(三)---struts2中的服务端数据验证框架validate

    struts2为我们提供了一个很好的数据验证框架–validate,该框架可以很方便的实现服务端的数据验证. ActionSupport类提供了一个validate()方法,当我们需要在某一个acti ...

  4. 【Java EE 学习 35 下】【struts2】【struts2文件上传】【struts2自定义拦截器】【struts2手动验证】

    一.struts2文件上传 1.上传文件的时候要求必须使得表单的enctype属性设置为multipart/form-data,把它的method属性设置为post 2.上传单个文件的时候需要在Act ...

  5. Struts2入门2 Struts2深入

    Struts2入门2 Struts2深入 链接: http://pan.baidu.com/s/1rdCDh 密码: sm5h 前言: 前面学习那一节,搞得我是在是太痛苦了.因为在Web项目中确实不知 ...

  6. Android Studio新建Jni工程

    2.2版本的Android Studio支持新建Jni工程,不用再像以前自己构建工程目录,首先把自己的升级自己的AS到2.2以上 然后打开Tools->Andorid->SDK manag ...

  7. Keil MDK入门---从新建一个工程开始

    熟悉Keil C51的朋友对于Keil MDK上手应该比较容易,毕竟界面是很像的.但ARM内核毕竟不同于51内核,因此无论在设置上还是在编程思想上,都需要下番功夫研究的.本文以MDK V4.03为例, ...

  8. IAR新建MSP430工程

    一.在IAR官网下载IAR for MSP430 软件 https://www.iar.com/iar-embedded-workbench/#!?architecture= 选择MSP430,然后 ...

  9. CCS 6新建TMS320F2812工程

    准备材料 CCS6 下载地址:http://www.ti.com/tool/ccstudio F2812的C语言头文件 下载地址:http://www.ti.com/lit/zip/sprc097 安 ...

  10. 如何在Flash Builder里新建ActionScript工程

    新建ActionScript工程 1. File > New > ActionScript Project 2. 按照提示完成工程的创建 使程序直接在Flash Player中运行 1. ...

随机推荐

  1. 为什么我们要使用min-height和max-height样式属性?

    Css min-height应用地方解释我们有时设置一个对象盒子时候避免对象没有内容时候不能撑开,但内容多少不能确定所以又不能固定高度,这个时候我们就会需要css来设置min-height最小高度撑高 ...

  2. 【BZOJ2473/2120】维护队列 分块+二分

    Description 你小时候玩过弹珠吗? 小朋友A有一些弹珠,A喜欢把它们排成队列,从左到右编号为1到N.为了整个队列鲜艳美观,小朋友想知道某一段连续弹珠中,不同颜色的弹珠有多少.当然,A有时候会 ...

  3. MySQL 服务无法启动。服务没有报告任何错误。

    MySQL数据库在升级到5.7版本后,和之前的版本有些不一样,没有data文件夹,我们都知道MySQL数据库文件是保存在data文件夹中的,网上有人说把5.6版本的data文件夹拷贝一个,这种说法听听 ...

  4. UIView常见属性总结

    一 UIVIew 常见属性 .frame 位置和尺寸(以父控件的左上角为原点(,)) .center 中点 (以父控件的左上角为原点(,)) .bounds 位置和尺寸(以自己的左上角为原点 (,)) ...

  5. 关于Repeater嵌套绑定的问题

    前台代码: <div id="firstpane" class="menu_list">                <asp:Repeat ...

  6. Objective-C的新特性

    Objective-C的新特性 苹果在今年的 WWDC2012 大会上介绍了大量 Objective-C 的新特性,能够帮助 iOS 程序员更加高效地编写代码.在不久前更新的 Xcode4.4 版本中 ...

  7. 聚合函数:sum,avg,max,min,count

    group by  分组的使用方法 数学函数:ABS.ceiling.floor.power.round.sqrt.square 练习:

  8. Hadoop.2.x_HA部署

    一.概念与HA思路 1. 首先Hadoop架构为主从架构(NameNode/DataNode) 2. NameNode管理着文件系统和与维护客户端访问DataNode 3. Hadoop 2.0 之前 ...

  9. PCTUSED和PCTFREE对数据操作的影响

    1概念理解 首先PCTUSED和PCTFREE都是针对数据块的存储属性,单位都是%.其中PCTFREE决定了数据块什么时候从free list中移除,系统就不可以再往该数据块中插入数据,对于数据块中已 ...

  10. VMwareTools安装笔记

    1.首先确保你的虚拟机正在运行. 2.右键点击“安装VMwareTools”,如果安装过了,会显示“重新安装...” 3.系统会自动打开VMwareTools的目录,(一般都会自动打开,因为系统一般会 ...