FORM验证简单demo
详解稍后加入。
项目结构如图:
web.xml
<?xml version="1.0" encoding="UTF-8" ?>
<web-app 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
"> <!-- 初始化日志系统 -->
<listener>
<listener-class>com.alibaba.citrus.logconfig.LogConfiguratorListener</listener-class>
</listener> <!-- 装载/WEB-INF/webx.xml, /WEB-INF/webx-*.xml -->
<listener>
<listener-class>com.alibaba.citrus.webx.context.WebxContextLoaderListener</listener-class>
</listener> <filter>
<filter-name>mdc</filter-name>
<filter-class>com.alibaba.citrus.webx.servlet.SetLoggingContextFilter</filter-class>
</filter> <filter>
<filter-name>webx</filter-name>
<filter-class>com.alibaba.citrus.webx.servlet.WebxFrameworkFilter</filter-class>
<init-param>
<param-name>excludes</param-name>
<param-value><!-- 须要被“排除”的URL路径,以逗号分隔,如/static, *.jpg。适合于映射静态页面、图片。 --></param-value>
</init-param>
<init-param>
<param-name>passthru</param-name>
<param-value><!-- 须要被“略过”的URL路径,以逗号分隔,如/myservlet, *.jsp。适用于映射servlet、filter。
对于passthru请求,webx的request-contexts服务、错误处理、开发模式等服务仍然可用。 --></param-value>
</init-param>
</filter> <filter-mapping>
<filter-name>mdc</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <filter-mapping>
<filter-name>webx</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>
webx.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Webx Root Context Configuration. -->
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:services="http://www.alibaba.com/schema/services"
xmlns:request-contexts="http://www.alibaba.com/schema/services/request-contexts"
xmlns:session-encoders="http://www.alibaba.com/schema/services/request-contexts/session/encoders"
xmlns:model-encoders="http://www.alibaba.com/schema/services/request-contexts/session/model-encoders"
xmlns:session-idgens="http://www.alibaba.com/schema/services/request-contexts/session/idgens"
xmlns:session-stores="http://www.alibaba.com/schema/services/request-contexts/session/stores"
xmlns:ml-adapters="http://www.alibaba.com/schema/services/module-loader/adapters"
xmlns:ml-factories="http://www.alibaba.com/schema/services/module-loader/factories"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
http://www.alibaba.com/schema/services/request-contexts http://localhost:8080/schema/services-request-contexts.xsd
http://www.alibaba.com/schema/services/request-contexts/session/encoders http://localhost:8080/schema/services-request-contexts-session-encoders.xsd
http://www.alibaba.com/schema/services/request-contexts/session/idgens http://localhost:8080/schema/services-request-contexts-session-idgens.xsd
http://www.alibaba.com/schema/services/request-contexts/session/stores http://localhost:8080/schema/services-request-contexts-session-stores.xsd
http://www.alibaba.com/schema/services/request-contexts/session/model-encoders http://localhost:8080/schema/services-request-contexts-session-model-encoders.xsd
http://www.alibaba.com/schema/services/module-loader/adapters http://localhost:8080/schema/services-module-loader-adapters.xsd
http://www.alibaba.com/schema/services/module-loader/factories http://localhost:8080/schema/services-module-loader-factories.xsd
http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
"> <!-- 支持${xxx}替换。 -->
<services:property-placeholder>
<services:property key="component">common</services:property>
</services:property-placeholder> <!-- 共享配置。 -->
<beans:import resource="common/webx-component-and-root.xml" /> <!-- 异常管道。 -->
<beans:import resource="common/pipeline-exception.xml" /> <!-- 资源装载。 -->
<beans:import resource="common/resources.xml" /> <!-- URI生成。 -->
<beans:import resource="common/uris.xml" /> <!-- 综合设置。 -->
<services:webx-configuration>
<!-- 默认将productionMode设为true,建议在jetty插件中设置-DproductionMode=false。 -->
<services:productionMode>${productionMode:true}</services:productionMode>
<services:components defaultComponent="app1" />
</services:webx-configuration> <!-- 设置request/response/session。 -->
<services:request-contexts xmlns="http://www.alibaba.com/schema/services/request-contexts">
<basic />
<buffered />
<lazy-commit />
<parser />
<set-locale defaultLocale="zh_CN" defaultCharset="UTF-8" />
<session>
<id>
<cookie path="/" maxAge="0" httpOnly="true" />
</id>
<stores>
<session-stores:cookie-store id="temporaryCookie">
<session-stores:cookie name="tmp" />
</session-stores:cookie-store>
</stores>
<store-mappings>
<match name="*" store="temporaryCookie" />
</store-mappings>
</session>
</services:request-contexts> <!-- 支持上传文件。 -->
<services:upload sizeMax="5M" /> <!-- 将beans暴露给模板。这里定义的tools可被全部components之间共享。 -->
<services:pull xmlns="http://www.alibaba.com/schema/services/pull/factories">
<utils />
<page-tool />
<control-tool />
<uris-tool />
</services:pull> <!-- 装载模块。 -->
<services:module-loader>
<ml-factories:class-modules>
<ml-factories:search-packages type="$1" packages="com.alibaba.webx.tutorial1.common.module.*" />
</ml-factories:class-modules>
</services:module-loader> </beans:beans>
webx-app1.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Webx Sub Context Configuration. -->
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:services="http://www.alibaba.com/schema/services"
xmlns:ml-adapters="http://www.alibaba.com/schema/services/module-loader/adapters"
xmlns:ml-factories="http://www.alibaba.com/schema/services/module-loader/factories"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
http://www.alibaba.com/schema/services/module-loader/adapters http://localhost:8080/schema/services-module-loader-adapters.xsd
http://www.alibaba.com/schema/services/module-loader/factories http://localhost:8080/schema/services-module-loader-factories.xsd
http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
"> <!-- 支持${xxx}替换。 -->
<services:property-placeholder>
<services:property key="component">app1</services:property>
</services:property-placeholder> <!-- 共享配置。 -->
<beans:import resource="common/webx-component-and-root.xml" />
<beans:import resource="common/webx-component.xml" /> <!-- 运行管道。 -->
<beans:import resource="common/pipeline.xml" /> <!-- 表单验证。 -->
<beans:import resource="app1/form.xml" /> <!-- 装载模块。 -->
<services:module-loader>
<ml-factories:class-modules>
<ml-factories:search-packages type="$1" packages="com.alibaba.webx.tutorial1.app1.module.*" />
</ml-factories:class-modules>
</services:module-loader> </beans:beans>
default.xml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
#showHead ("My Simple Webx Application")
</head> <body #bodyAttributes ()>
<p> This is default</p>
$screen_placeholder <hr/>
<p>[<a href="$app1Link.setTarget("index")">Home</a>] [<a href="$app1Link">Dev Home</a>]</p> </body>
</html>
hello.vm
$page.setTitle("Hello, $name")
<p>Hello, $name!</p>
index.vm
<form action="$app1Link.setTarget("index")" method="post">
$csrfToken.hiddenField
<input type="hidden" name="action" value="simple_action"/> <p>Hello, what's your name?</p> #set($groupB = $form.simple.defaultInstance) <input type="text" name="$groupB.name.key" value="$!groupB.name.value"/>
<input type="text" name="$groupB.password.key" value="$!groupB.password.value"/> <input type="submit" name="event_submit_do_greeting"/> </form>
login.vm
$page.setTitle("Hello, $name")
<p>${name} is not valid</p>
form.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:services="http://www.alibaba.com/schema/services"
xmlns:fm-conditions="http://www.alibaba.com/schema/services/form/conditions"
xmlns:fm-validators="http://www.alibaba.com/schema/services/form/validators"
xmlns="http://www.alibaba.com/schema/services/form/validators"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
http://www.alibaba.com/schema/services/form/conditions http://localhost:8080/schema/services-form-conditions.xsd
http://www.alibaba.com/schema/services/form/validators http://localhost:8080/schema/services-form-validators.xsd
http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
"> <services:form postOnlyByDefault="true">
<!--
- ===============================================
- 用来检查csrf token。
- ===============================================
-->
<services:group name="csrfCheck">
<services:field name="csrfToken">
<csrf-validator>
<message>提交的数据已过期</message>
</csrf-validator>
</services:field>
</services:group>
<!--
- ===============================================
- Simple form
- ===============================================
-->
<services:group name="simple" extends="csrfCheck">
<services:field name="name" displayName="你的名字">
<required-validator>
<message>必须填写 ${displayName}</message>
</required-validator>
</services:field>
<services:field name="password" displayName="你的密码">
<required-validator>
<message>必须填写 ${displayName}</message>
</required-validator>
</services:field>
</services:group>
</services:form> </beans:beans>
simpleAction.java
/*
* Copyright 2010 Alibaba Group Holding Limited.
* All rights reserved.
*
* Licensed 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 com.alibaba.webx.tutorial1.app1.module.action; import java.util.List; import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.FormGroup; import com.alibaba.webx.tutorial1.app1.SimpleObject; public class SimpleAction {
public void doGreeting(@FormGroup("simple") SimpleObject simple, Navigator nav) throws Exception { String name = simple.getName();
String password=simple.getPassword(); if("LTianchao".equals(name)&&("123".equals(password))){
nav.redirectTo("app1Link").withTarget("hello").withParameter("name", name); }
else
nav.redirectTo("app1Link").withTarget("login").withParameter("name", name);
System.out.println("action begin");
System.out.println("done"); //、、context.put("name",simple[1].getName()); }
}
hello.java
/*
* Copyright 2010 Alibaba Group Holding Limited.
* All rights reserved.
*
* Licensed 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 com.alibaba.webx.tutorial1.app1.module.screen; import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.dataresolver.Param; public class Hello {
public void execute(@Param("name") String name, Context context) {
context.put("name", name);
}
}
login.java
/*
* Copyright 2010 Alibaba Group Holding Limited.
* All rights reserved.
*
* Licensed 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 com.alibaba.webx.tutorial1.app1.module.screen; import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.dataresolver.Param; public class login {
public void execute(@Param("name") String name, Context context) {
context.put("name", name);
}
}
SimleObject.java
/*
* Copyright 2010 Alibaba Group Holding Limited.
* All rights reserved.
*
* Licensed 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 com.alibaba.webx.tutorial1.app1; public class SimpleObject {
private String name;
private String password; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} }
FORM验证简单demo的更多相关文章
- jquery实现表单验证简单实例
/* 描述:基于jquery的表单验证插件. */ (function ($) { $.fn.checkForm = function (options) { var root = this; //将 ...
- Nodejs之MEAN栈开发(四)---- form验证及图片上传
这一节增加推荐图书的提交和删除功能,来学习node的form提交以及node的图片上传功能.开始之前需要源码同学可以先在git上fork:https://github.com/stoneniqiu/R ...
- Asp.Net Form验证不通过,重复登录
问题产生根源: 当然,其实应该需要保持线上所有机器环境一致!可是,写了一个小程序.使用的是4.5,aysnc/await实在太好用了,真心不想把代码修改回去. so,动了念头,在这台服务器上装个4.5 ...
- form验证及图片上传
form验证及图片上传 这一节增加推荐图书的提交和删除功能,来学习node的form提交以及node的图片上传功能.开始之前需要源码同学可以先在git上fork:https://github.com/ ...
- Python Django的分页,Form验证,中间件
本节内容 Django的分页 Form 中间件 1 Django 分页 1.1 Django自带的分页 1.首先来看下我的测试数据环境 ############ models.py ######### ...
- python自动化开发-[第二十一天]-form验证,中间件,缓存,信号,admin后台
今日概要: 1.form表单进阶 2.中间件 3.缓存 4.信号 5.admin后台 上节课回顾 FBV,CBV 序列化 - Django内置 - json.dumps(xxx,cls=) Form验 ...
- 04: Form 验证用户数据 & 生成html
目录:Django其他篇 01:Django基础篇 02:Django进阶篇 03:Django数据库操作--->Model 04: Form 验证用户数据 & 生成html 05:Mo ...
- Asp.Net Form验证不通过,重复登录(.net4,4.5form验证兼容性问题)
问题产生根源: 当然,其实应该需要保持线上所有机器环境一致!可是,写了一个小程序.使用的是4.5,aysnc/await实在太好用了,真心不想把代码修改回去. so,动了念头,在这台服务器上装个4.5 ...
- Django 进阶篇之 Form验证
Django Form验证 在实际的生产环境中比如登录和验证的时候,我们一般都使用Jquery+ajax来判断用户的输入是否为空,假如JS被禁用的话,咱们这个认证屏障是不是就消失了呢?(虽然一般不会禁 ...
随机推荐
- for循环语句之棋盘放粮食、百鸡百钱、纸张的折叠问题
1.棋盘放粮食 ; ; i < ; i++) { ; ; j <= i; j++) { x = x * ; } lszl = lszl + x; } double zl = lszl * ...
- CentOS安装rar及用法
1.下载安装rar wget http://www.rarsoft.com/rar/rarlinux-x64-5.4.b3.tar.gztar -zxvf rarlinux-x64-.tar.gz - ...
- c语言 ,回调函数[个人理解]
回调函数:把需要调用的方法的指针pCallBackFuncX作为参数传递给一个函数UsrFunction,以便该UsrFunction函数在处理相似事件的时候可以灵活的使用不同的方法. 以在fla ...
- BZOJ 3282: Tree( LCT )
LCT.. -------------------------------------------------------------------------------- #include<c ...
- js 易错点
如下代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- 用Flask实现视频数据流传输
Flask 是一个 Python 实现的 Web 开发微框架.这篇文章是一个讲述如何用它实现传送视频数据流的详细教程. 我敢肯定,现在你已经知道我在O’Reilly Media上发布了有关Flask的 ...
- Codeforces 509C Sums of Digits 贪心
这道题目有人用DFS.有人用DP 我觉得还是最简单的贪心解决也是不错的选择. Ok,不废话了,这道题目的意思就是 原先存在一个严格递增的Arrary_A,然后Array_A[i] 的每位之和为Arra ...
- python模块学习---HTMLParser(解析HTML文档元素)
HTMLParser是Python自带的模块,使用简单,能够很容易的实现HTML文件的分析. 本文主要简单讲一下HTMLParser的用法. 使用时需要定义一个从类HTMLParser继承的类,重定义 ...
- Sql语句中使用参数化的Top
在sql中使用参数化的Top,Top后面的参数要用括号括起来. 例如: select top (@ts) ID, [Type], Title, Content, LinkMan, Tel, Check ...
- BZOJ 2318: Spoj4060 game with probability Problem( 概率dp )
概率dp... http://blog.csdn.net/Vmurder/article/details/46467899 ( from : [辗转山河弋流歌 by 空灰冰魂] ) 这个讲得很好 , ...