Struts-2.3.24.1官方例子-struts2-blank

一、配置文件

1.web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 5
 6     <display-name>Struts Blank</display-name>
 7
 8     <filter>
 9         <filter-name>struts2</filter-name>
10         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
11     </filter>
12
13     <filter-mapping>
14         <filter-name>struts2</filter-name>
15         <url-pattern>/*</url-pattern>
16     </filter-mapping>
17
18     <welcome-file-list>
19         <welcome-file>index.html</welcome-file>
20     </welcome-file-list>
21
22     <!-- Restricts access to pure JSP files - access available only via Struts action -->
23     <security-constraint>
24         <display-name>No direct JSP access</display-name>
25         <web-resource-collection>
26             <web-resource-name>No-JSP</web-resource-name>
27             <url-pattern>*.jsp</url-pattern>
28         </web-resource-collection>
29         <auth-constraint>
30             <role-name>no-users</role-name>
31         </auth-constraint>
32     </security-constraint>
33
34     <security-role>
35         <description>Don‘t assign users to this role</description>
36         <role-name>no-users</role-name>
37     </security-role>
38
39 </web-app>

2.struts.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 4     "http://struts.apache.org/dtds/struts-2.3.dtd">
 5
 6 <struts>
 7
 8     <constant name="struts.enable.DynamicMethodInvocation" value="false" />
 9     <constant name="struts.devMode" value="true" />
10
11     <package name="default" namespace="/" extends="struts-default">
12
13         <default-action-ref name="index" />
14
15         <global-results>
16             <result name="error">/WEB-INF/jsp/error.jsp</result>
17         </global-results>
18
19         <global-exception-mappings>
20             <exception-mapping exception="java.lang.Exception" result="error"/>
21         </global-exception-mappings>
22
23         <action name="index">
24             <result type="redirectAction">
25                 <param name="actionName">HelloWorld</param>
26                 <param name="namespace">/example</param>
27             </result>
28         </action>
29     </package>
30
31     <include file="example.xml"/>
32
33     <!-- Add packages here -->
34
35 </struts>

3.example.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3         "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 4         "http://struts.apache.org/dtds/struts-2.0.dtd">
 5
 6 <struts>
 7     <package name="example" namespace="/example" extends="default">
 8
 9         <action name="HelloWorld" class="example.HelloWorld">
10             <result>/WEB-INF/jsp/example/HelloWorld.jsp</result>
11         </action>
12
13         <action name="Login_*" method="{1}" class="example.Login">
14             <result name="input">/WEB-INF/jsp/example/Login.jsp</result>
15             <result type="redirectAction">Menu</result>
16         </action>
17
18         <action name="*" class="example.ExampleSupport">
19             <result>/WEB-INF/jsp/example/{1}.jsp</result>
20         </action>
21
22         <!-- Add actions here -->
23     </package>
24 </struts>

4.

二、action

1.

 1 /*
 2  * $Id$
 3  *
 4  * Licensed to the Apache Software Foundation (ASF) under one
 5  * or more contributor license agreements.  See the NOTICE file
 6  * distributed with this work for additional information
 7  * regarding copyright ownership.  The ASF licenses this file
 8  * to you under the Apache License, Version 2.0 (the
 9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 package example;
23
24 import com.opensymphony.xwork2.ActionSupport;
25
26 /**
27  * Base Action class for the Tutorial package.
28  */
29 public class ExampleSupport extends ActionSupport {
30 }

2.

 1 /*
 2  * $Id$
 3  *
 4  * Licensed to the Apache Software Foundation (ASF) under one
 5  * or more contributor license agreements.  See the NOTICE file
 6  * distributed with this work for additional information
 7  * regarding copyright ownership.  The ASF licenses this file
 8  * to you under the Apache License, Version 2.0 (the
 9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 package example;
23
24 import java.util.Arrays;
25 import java.util.List;
26
27 /**
28  * <code>Set welcome message.</code>
29  */
30 public class HelloWorld extends ExampleSupport {
31
32     public String execute() throws Exception {
33         setMessage(getText(MESSAGE));
34         return SUCCESS;
35     }
36
37     /**
38      * Provide default valuie for Message property.
39      */
40     public static final String MESSAGE = "HelloWorld.message";
41
42     /**
43      * Field for Message property.
44      */
45     private String message;
46
47     /**
48      * Return Message property.
49      *
50      * @return Message property
51      */
52     public String getMessage() {
53         return message;
54     }
55
56     /**
57      * Set Message property.
58      *
59      * @param message Text to display on HelloWorld page.
60      */
61     public void setMessage(String message) {
62         this.message = message;
63     }
64
65     public List<YesNo> getValues() {
66 //        return null;
67         return Arrays.asList(YesNo.values());
68     }
69 }

3.

 1 /*
 2  * $Id$
 3  *
 4  * Licensed to the Apache Software Foundation (ASF) under one
 5  * or more contributor license agreements.  See the NOTICE file
 6  * distributed with this work for additional information
 7  * regarding copyright ownership.  The ASF licenses this file
 8  * to you under the Apache License, Version 2.0 (the
 9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 package example;
23
24 import org.apache.struts2.interceptor.validation.SkipValidation;
25
26 public class Login extends ExampleSupport {
27
28     @Override
29     public String execute() throws Exception {
30         return SUCCESS;
31     }
32
33     @SkipValidation
34     public String form() throws Exception {
35         return INPUT;
36     }
37
38     private String username;
39
40     public String getUsername() {
41         return username;
42     }
43
44     public void setUsername(String username) {
45         this.username = username;
46     }
47
48     private String password;
49
50     public String getPassword() {
51         return password;
52     }
53
54     public void setPassword(String password) {
55         this.password = password;
56     }
57
58 }

4.

1 package example;
2
3 public enum YesNo {
4     YES, NO, middle
5 }

三、JSP

1.HelloWorld.jsp

 1 <%@ page contentType="text/html; charset=UTF-8" %>
 2 <%@ taglib prefix="s" uri="/struts-tags" %>
 3 <html>
 4 <head>
 5     <title><s:text name="HelloWorld.message"/></title>
 6 </head>
 7
 8 <body>
 9 <h2><s:property value="message"/></h2>
10
11 <h3>Languages</h3>
12 <ul>
13     <li>
14         <s:url id="url" action="HelloWorld">
15             <s:param name="request_locale">en</s:param>
16         </s:url>
17         <s:a class="test" href="%{url}">English</s:a>
18     </li>
19     <li>
20         <s:url id="url" action="HelloWorld">
21             <s:param name="request_locale">es</s:param>
22         </s:url>
23         <s:a href="%{url}">Espanol</s:a>
24     </li>
25 </ul>
26
27 <!-- 在package.properties配置信息 -->
28 <s:checkboxlist name="test" list="values" listLabelKey="‘test-‘ + name().toLowerCase()" />
29
30 </body>
31 </html>

2.Login.jsp

 1 <%@ page contentType="text/html; charset=UTF-8" %>
 2 <%@ taglib prefix="s" uri="/struts-tags" %>
 3 <html>
 4 <head>
 5     <title>Sign On</title>
 6 </head>
 7
 8 <body>
 9 <s:form action="Login">
10     <s:textfield key="username"/>
11     <s:password key="password" />
12     <s:submit/>
13 </s:form>
14 </body>
15 </html>

3.Menu.jsp

1 <%@ page contentType="text/html; charset=UTF-8" %>
2 <%@ taglib prefix="s" uri="/struts-tags" %>
3 <s:include value="Missing.jsp"/>

4.Missing.jsp

 1 <%@ page contentType="text/html; charset=UTF-8" %>
 2 <%@ taglib prefix="s" uri="/struts-tags" %>
 3 <html>
 4 <head><title>Missing Feature</title></head>
 5
 6 <body>
 7 <p>
 8     <s:text name="Missing.message"/>
 9 </p>
10 </body>
11 </html>

5.Register.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:include value="Missing.jsp"/>

6.Welcome.jsp

 1 <%@ page contentType="text/html; charset=UTF-8" %>
 2 <%@ taglib prefix="s" uri="/struts-tags" %>
 3 <html>
 4 <head>
 5     <title>Welcome</title>
 6     <link href="<s:url value="/css/examplecss"/>" rel="stylesheet"
 7           type="text/css"/>
 8 </head>
 9
10 <body>
11 <h3>Commands</h3>
12 <ul>
13     <li><a href="<s:url action="Login_input"/>">Sign On</a></li>
14     <li><a href="<s:url action="Register"/>">Register</a></li>
15 </ul>
16
17 </body>
18 </html>

7.

四、资源文件等

1.package.properies

1 HelloWorld.message= Struts is up and running ...
2 requiredstring = ${getText(fieldName)} is required.
3 password = Password
4 username = User Name
5 Missing.message =  This feature is under construction. Please try again in the next interation.
6 test-yes=Yo
7 test-no=Nein
8 test-middle=mod

2.Login-validation.xml

 1 <!DOCTYPE validators PUBLIC
 2         "-//Apache Struts//XWork Validator 1.0.2//EN"
 3         "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
 4
 5 <validators>
 6     <field name="username">
 7         <field-validator type="requiredstring">
 8             <message key="requiredstring"/>
 9         </field-validator>
10     </field>
11     <field name="password">
12         <field-validator type="requiredstring">
13             <message key="requiredstring"/>
14         </field-validator>
15     </field>
16 </validators>

3.velocity.properies

1 runtime.log.logsystem.class=org.apache.velocity.runtime.log.NullLogChute
时间: 2024-10-11 12:22:19

Struts-2.3.24.1官方例子-struts2-blank的相关文章

Java Restful框架:Jersey入门示例(官方例子)

本文主要介绍了Java Restful框架Jersey入门例子(来源于官方网站https://jersey.java.net/),废话不多说进入正题. 在Jersey官方示例中(https://jersey.java.net/documentation/latest/getting-started.html),入门例子主要采用maven构建,在这里使用eclipse来创建我们的项目 1.使用maven 骨架方式创建项目,如下图, 2.,如果在eclipser中没有上面的选项,我们需要手动添加Je

android导入官方例子

android导入samplefile-->project-->Android-->Android Sample Project android导入官方例子,布布扣,bubuko.com

pyqt ColumnView, QFileSystemModel, QSplitter, QTreeView例子学习(由官方例子提供学习)

from PyQt4.QtGui import (QApplication, QColumnView, QFileSystemModel, QSplitter, QTreeView) #注意 """ QColumnView类提供了一个模型/视图列视图的实现,继承QAbstractItemView 提供了一个本地文件系统的数据模型,继承QAbstractItemModel 实现了一个分流器小部件,继承qframe 提供了一个默认的模型/视图树视图的实现,继承QAbstractI

【Struts2】Struts2纯手工安装、配置以及Helloworld,以最新版struts 2.3.20 GA做例子

许多网上的教程对Struts2的配置.安装弄得不明不白,很多高手以为小白是什么都懂,许多细节上面的地方没有说明清楚,甚至还有在Maven上面讲解的,要知道Struts2跟Maven没有半点的关系,完全可以像其它的javaweb插件那样在web.xml并且启动,同时复制那些包又没有说清楚,以致于按照各种教程的web.xml写好,之后,运行Tomcat一堆的错误,永远卡在Dispatcher initialization failed上面,半天出不来.弄得只好在已经配置好Struts的工程里面,直接

[Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes

链接地址:[Selecting Contents for Uber JAR](http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html) apache网站在国内打开太慢了.因此我将这些有用的资源收集起来,保存在博客中! Apache Maven Shade Plugin:是一个Maven打包的插件.其官网英文定义如下:This plugin provides the capability

(24) java web的struts2框架的使用-action参数自动封装与类型转换

structs可以对参数进行自动封装,做法也很简单. 一,action参数自动封装: 1,可以直接在action类中,声明public的属性,接受参数. 2,属性也是是private,如果是private,需要提供setter方法,也可以根据需要提供getter方法. 3,struts可以自动对类型进行转换,一般我们会传递String类型的参数,struts可以转换成默认声明的变量类型 4,调用api时候,传递的参数名必须和action类中声明的名称相同. public class UserAc

Mxnet使用TensorRT加速模型--Mxnet官方例子

官方示例链接 https://mxnet.apache.org/api/python/docs/tutorials/performance/backend/tensorrt/tensorrt.html   Optimizing Deep Learning Computation Graphs with TensorRT   本文档代码来源于mxnet官方网站翻译,添加自己运行情况.NVIDIA的TensorRT是用于加速网络推理的深度学习库,Mxnet的1.3.0版本开始试验性质的支持Tenso

NDK的OpenGLes2.0 官方例子解析

提要 NDK自带了一个OpenGLes的例子,下面就一起来学习一下. 环境:Ubuntu14.04 NDK r10 ADT13.02 Android Native Development Tools 8.12 注:在ubuntu的adt需要手动安装Android Native Development Tools才能很好的支持NDK. 如果你对Java调用C/C++的代码还不了解,可以参考:JNI原理及实现 利用JNI进行对象操作 如果你对NDK还不了解,可以参考:Android的NDK开发(1)

werkzeug模版学习-官方例子Shortly分析

为了学习werkzeug的wsgi框架工具,今天真对官网的例子进行调试运行.涉及到了werkzeug工具包,jinja2前端模版,以及redis内存库,之后可以灵活定制自己主页.再次,作以记录. 首先,参考官网流程完成部署,当然,Python2和Python3有一定区别,需要大家注意,官网代码都是一句Python2.7的.这里主要涉及到在2.7中可以import urlparse,但3.5中需要用urllib.parse.urlparse. 官网:http://werkzeug.pocoo.or