Join in 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> <! -- The URL paths to be excluded are 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> <! -- The URL path to be skipped must be 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"/> <! -- Run the MPs queue. --> <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; } }