FORM Verification simple demo

Source: Internet
Author: User

For more information, see add later.

Project Structure


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"> <! -- Initialize the log system --> <listener-class> com. alibaba. citrus. logconfig. LogConfiguratorListener </listener-class> </listener> <! -- Load/WEB-INF/webx. xml/WEB-INF/webx -*. xml --> <listener-class> com. alibaba. citrus. webx. context. webxContextLoaderListener </listener-class> </listener> <filter-name> mdc </filter-name> <filter-class> com. alibaba. citrus. webx. servlet. setLoggingContextFilter </filter-class> </filter> <filter-name> webx </filter-name> <filter-class> com. alibaba. citrus. webx. servlet. webxFrameworkFilt Er </filter-class> <init-param> <param-name> excludes </param-name> <param-value> <! -- URL paths to be excluded, separated by commas (,), such as/static, *. jpg. It is suitable for ing static pages and images. --> </Param-value> </init-param> <param-name> passthru </param-name> <param-value> <! -- URL paths that need to be skipped are separated by commas, such as/myservlet, *. jsp. It is applicable to servlet and filter ing. For passthru requests, the webx request-contexts service, error handling, development mode, and other services are still available. --> </Param-value> </init-param> </filter> <filter-mapping> <filter-name> mdc </filter-name> <url-pattern> /* </url-pattern> </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: l-factories = "http://www.alibaba.com/schema/services/module-loader/factories" xmln S: 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/r Equest-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.springframew Ork.org/schema/beans http: // localhost: 8080/schema/www.springframework.org/schema/beans/spring-beans.xsd "> <! -- $ {Xxx} can be replaced. --> <Services: property-placeholder> <services: property key = "component"> common </services: property> </services: property-placeholder> <! -- Share configuration. --> <Beans: import resource = "common/webx-component-and-root.xml"/> <! -- Exception MPs queue. --> <Beans: import resource = "common/pipeline-exception.xml"/> <! -- Load resources. --> <Beans: import resource = "common/resources. xml"/> <! -- URI generation. --> <Beans: import resource = "common/uris. xml"/> <! -- Comprehensive settings. --> <Services: webx-configuration> <! -- The productionMode is set to true by default. We recommend that you set-DproductionMode = false in the jetty plug-in. --> <Services: productionMode >$ {productionMode: true} </services: productionMode> <services: components defaultComponent = "app1"/> </services: webx-configuration> <! -- Set 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> <! -- Supports file upload. --> <Services: upload sizeMax = "5 M"/> <! -- Expose beans to the template. The tools defined here can be shared by all components. --> <Services: pull xmlns = "http://www.alibaba.com/schema/services/pull/factories"> <utils/> <page-tool/> <control-tool/> <uris-tool/> </services: pull> <! -- Load the module. --> <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: // w Ww.springframework.org/schema/beans http: // localhost: 8080/schema/www.springframework.org/schema/beans/spring-beans.xsd "> <! -- $ {Xxx} can be replaced. --> <Services: property-placeholder> <services: property key = "component"> app1 </services: property> </services: property-placeholder> <! -- Share configuration. --> <Beans: import resource = "common/webx-component-and-root.xml"/> <beans: import resource = "common/webx-component.xml"/> <! -- Execution pipeline. --> <Beans: import resource = "common/pipeline. xml"/> <! -- Form verification. --> <Beans: import resource = "app1/form. xml"/> <! -- Load the module. --> <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">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" xml Ns: 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.springframewor K.org/schema/beans http: // localhost: 8080/schema/www.springframework.org/schema/beans/spring-beans.xsd "> <services: form postOnlyByDefault =" true "> <! ---= ==========- Used to check the csrf token. -============================================== =========--> <Services: group name = "csrfCheck"> <services: field name = "csrfToken"> <csrf-validator> <message> the submitted data has expired </message> </csrf-validator> </services: field> </services: group> <! ---= ===========- Simple form-======================================= ===================================--> <services: group name = "simple" extends = "csrfCheck"> <services: field name = "name" displayName = "Your name"> <required-validator> <message> $ {displayName} </message> </required-validator> </ services: field> <services: field name = "password" displayName = "your password"> <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;    }  }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.