标签:style blog class code java tar
1 <?xml version="1.0" encoding="UTF-8"?>
2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
5 id="WebApp_ID" version="2.5">
6
7 <display-name>Struts2</display-name>
8
9 <!-- Struts2配置 -->
10 <filter>
11 <filter-name>struts2</filter-name>
12 <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
13 </filter>
14 <filter-mapping>
15 <filter-name>struts2</filter-name>
16 <url-pattern>/*</url-pattern>
17 </filter-mapping>
18 <!-- -->
19 <!-- org.apache.struts2.dispatcher.FilterDispatcher -->
20
21 <welcome-file-list>
22 <welcome-file>index.jsp</welcome-file>
23 </welcome-file-list>
24
25 </web-app>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
3 "http://struts.apache.org/dtds/struts-2.0.dtd">
4 <struts>
5 <package name="packageName" extends="struts-default">
6 <action name="LogicName" class="CustomerAction">
7 <result name="ResultString">Jsp file</result>
8 <result name="Result">Jsp file</result>
9 </action>
10 </package>
11 </struts>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 <%@taglib prefix="s" uri="/struts-tags" %> 3 <html> 4 <head><title>Insert title here</title></head> 5 <body> 6 <h3><s:text name=“login.title”/></h3> 7 <s:form action="login"> 8 <s:textfield name="name" key="login.name“/> 9 <s:password name="password" key=“login.password“/> 10 <s:submit value="Submit"/> 11 </s:form> 12 </body> 13 </html>
1 public class LoginAction{ 2 private String name; 3 private String password; 4 public String getName() {return name;} 5 public void setName(String name) {this. name = name;} 6 public String getPassword() {return password;} 7 public void setPassword(String password) {this.password = password;} 8 public String execute()throws Exception{ 9 if(getName().equals("scott")&&getPassword().equals("tiger")){ 10 ActionContext.getContext().getSession().put("name", getName()); 11 return "success"; 12 }else{ 13 return "error"; 14 } 15 } }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 3 "http://struts.apache.org/dtds/struts-2.0.dtd"> 4 <struts> 5 <constant name="struts.custom.i18n.resources" value="messageResource" /> 6 <package name="ch02" extends="struts-default"> 7 <action name=“login" class=“basic.struts.LoginAction"> 8 <result name="input">/login.jsp</result> 9 <result name="error">/error.jsp</result> 10 <result name="success">/welcome.jsp</result> 11 </action> 12 </package>
标签:style blog class code java tar
原文地址:http://www.cnblogs.com/sunhongyu/p/3714438.html