一、配置文件

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

2.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.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results>
<result name="error">/WEB-INF/jsp/error.jsp</result>
</global-results> <global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings> <action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package> <include file="example.xml"/> <!-- Add packages here --> </struts>

3.example.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>
<package name="example" namespace="/example" extends="default"> <action name="HelloWorld" class="example.HelloWorld">
<result>/WEB-INF/jsp/example/HelloWorld.jsp</result>
</action> <action name="Login_*" method="{1}" class="example.Login">
<result name="input">/WEB-INF/jsp/example/Login.jsp</result>
<result type="redirectAction">Menu</result>
</action> <action name="*" class="example.ExampleSupport">
<result>/WEB-INF/jsp/example/{1}.jsp</result>
</action> <!-- Add actions here -->
</package>
</struts>

4.

二、action

1.

 /*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ package example; import com.opensymphony.xwork2.ActionSupport; /**
* Base Action class for the Tutorial package.
*/
public class ExampleSupport extends ActionSupport {
}

2.

 /*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ package example; import java.util.Arrays;
import java.util.List; /**
* <code>Set welcome message.</code>
*/
public class HelloWorld extends ExampleSupport { public String execute() throws Exception {
setMessage(getText(MESSAGE));
return SUCCESS;
} /**
* Provide default valuie for Message property.
*/
public static final String MESSAGE = "HelloWorld.message"; /**
* Field for Message property.
*/
private String message; /**
* Return Message property.
*
* @return Message property
*/
public String getMessage() {
return message;
} /**
* Set Message property.
*
* @param message Text to display on HelloWorld page.
*/
public void setMessage(String message) {
this.message = message;
} public List<YesNo> getValues() {
// return null;
return Arrays.asList(YesNo.values());
}
}

3.

 /*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ package example; import org.apache.struts2.interceptor.validation.SkipValidation; public class Login extends ExampleSupport { @Override
public String execute() throws Exception {
return SUCCESS;
} @SkipValidation
public String form() throws Exception {
return INPUT;
} private String username; public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} private String password; public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} }

4.

 package example;

 public enum YesNo {
YES, NO, middle
}

三、JSP

1.HelloWorld.jsp

 <%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title><s:text name="HelloWorld.message"/></title>
</head> <body>
<h2><s:property value="message"/></h2> <h3>Languages</h3>
<ul>
<li>
<s:url id="url" action="HelloWorld">
<s:param name="request_locale">en</s:param>
</s:url>
<s:a class="test" href="%{url}">English</s:a>
</li>
<li>
<s:url id="url" action="HelloWorld">
<s:param name="request_locale">es</s:param>
</s:url>
<s:a href="%{url}">Espanol</s:a>
</li>
</ul> <!-- 在package.properties配置信息 -->
<s:checkboxlist name="test" list="values" listLabelKey="'test-' + name().toLowerCase()" /> </body>
</html>

2.Login.jsp

 <%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Sign On</title>
</head> <body>
<s:form action="Login">
<s:textfield key="username"/>
<s:password key="password" />
<s:submit/>
</s:form>
</body>
</html>

3.Menu.jsp

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

4.Missing.jsp

 <%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head><title>Missing Feature</title></head> <body>
<p>
<s:text name="Missing.message"/>
</p>
</body>
</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

 <%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Welcome</title>
<link href="<s:url value="/css/examplecss"/>" rel="stylesheet"
type="text/css"/>
</head> <body>
<h3>Commands</h3>
<ul>
<li><a href="<s:url action="Login_input"/>">Sign On</a></li>
<li><a href="<s:url action="Register"/>">Register</a></li>
</ul> </body>
</html>

7.

四、资源文件等

1.package.properies

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

2.Login-validation.xml

 <!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.2//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd"> <validators>
<field name="username">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
</validators>

3.velocity.properies

 runtime.log.logsystem.class=org.apache.velocity.runtime.log.NullLogChute

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

  1. Struts 2.3.24源码解析+Struts2拦截参数,处理请求,返回到前台过程详析

    Struts2官网:http://struts.apache.org/ 目前最新版本:Struts 2.3.24 Struts1已经完全被淘汰了,而Struts2是借鉴了webwork的设计理念而设计 ...

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

    本文主要介绍了Java Restful框架Jersey入门例子(来源于官方网站https://jersey.java.net/),废话不多说进入正题. 在Jersey官方示例中(https://jer ...

  3. 解析苹果的官方例子LazyTableImages实现图片懒加载原理

    解析苹果的官方例子LazyTableImages实现图片懒加载原理 首先在官网下载源码: https://developer.apple.com/library/ios/navigation/#sec ...

  4. [原][OE][官方例子]osgearth_annotation OE地球添加热点标签

    OE所有官方例子 OE代码样例 /* -*-c++-*- */ /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph * Co ...

  5. Struts2入门(一)——环境搭建和简单例子(Struts2 2.5.2版本)

    一.前言 1.了解三大框架 什么是框架? 框架是一种规范,一种规则,一种把技术组织起来的规则,这就是框架. 什么是三大框架(SSH),Struts.hibernate和spring的作用是什么? St ...

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

    链接地址:[Selecting Contents for Uber JAR](http://maven.apache.org/plugins/maven-shade-plugin/examples/i ...

  7. Struts 2(二):使用Struts2

    本文简单描述如何在Eclipse中使用使用Struts2,并介绍一下Struts2的配置文件 注:Struts2默认需要Java 5.0及其以上版本的运行环境支持,Web容器需要支持Servlet 2 ...

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

    structs可以对参数进行自动封装,做法也很简单. 一,action参数自动封装: 1,可以直接在action类中,声明public的属性,接受参数. 2,属性也是是private,如果是priva ...

  9. Netty入门官方例子

    参考链接:https://blog.csdn.net/wocjy/article/details/78661464 maven依赖: <!-- Netty开始 --> <!-- ht ...

随机推荐

  1. C++ typedef用法小结

    一.typedef的四个用法 用法一: 为复杂的声明定义一个新的简单的别名.方法是:在原来的声明里逐步用别名替换一部分复杂声明,如此循环,把带变量名的部分留到最后替换,得到的就是原声明的最简化版.举例 ...

  2. 04_例子讲解:rlViewDemo.exe

    参考资料:http://www.roboticslibrary.org/tutorials/first-steps-windows 使用rlViewDemo对应的快捷方式启动程序,可以看到如下界面: ...

  3. httpd 配置用户访问认证

    需求:单用户访问网站的某个目录,需要使用帐号密码来登录才能访问. 一.编辑虚拟主机的配置文件,添加目录级访问限制 <Directory "/var/www/html/demo" ...

  4. PHP 魔术方法 __get __set (二)

    慢慢长寻夜,明月高空挂 __get() - 读取不可访问属性的值时,__get() 会被调用 __set() - 在给不可访问属性赋值时,__set() 会被调用 <?php /** * 清晰的 ...

  5. tomcat6.0添加ssi(*.shtml)配置

    1.去掉tomcat6中conf/web.xml关于ssi的注释 <servlet> <servlet-name>ssi</servlet-name> <se ...

  6. 获取JAVA对象占用的内存大小

    介绍两种获取JAVA对象内存大小的方法. 第一种:Instrumentation 简介: 使用java.lang.instrument 的Instrumentation来获取一个对象的内存大小.利用I ...

  7. (转载)SQLServer存储过程返回值总结

    1. 存储过程没有返回值的情况(即存储过程语句中没有return之类的语句) 用方法 int count = ExecuteNonQuery(..)执行存储过程其返回值只有两种情况 (1)假如通过查询 ...

  8. CR0,CR3寄存器

    驱动在hook系统函数的时候通常要将只读属性暂时的屏蔽掉,主要有三种方法 1.修改CR0寄存器的WP位,使只读属性失效(这是网上用的最多的方法),切忌使用完之后立马修改回来 2.只读的虚拟地址,通过C ...

  9. MenuItem

    private void 文件ToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("打开测试" ...

  10. sort +awk+uniq 统计文件中出现次数最多的前10个单词

    实例cat logt.log|sort -s -t '-' -k1n |awk '{print $1;}'|uniq -c|sort -k1nr|head -100 统计文件中出现次数最多的前10个单 ...