S9.2_Struts2_OtherTag 常见的非UI标签

来源:互联网 发布:北京华道数据有限公司 编辑:程序博客网 时间:2024/04/28 11:57

非UI标签介绍
struts2类型转换

常见的非UI标签
bean
if
iterator
include
set
date
action
url

我们接下来将要创建的项目目录结构如下:


创建一个新项目S9.2_Struts2_OtherTag

创建第1个软件包net.nw.action

创建第2个软件包包net.nw.dao

创建第3个软件包net.nw.servlet

创建第4个软件包net.nw.vo

第1个软件包net.nw.action创建LoginAction2动作类 :

package net.nw.action;
import com.opensymphony.xwork2.ActionSupport;
import net.nw.dao.UserDao;
import net.nw.vo.User;

public class LoginAction2 extends ActionSupport {

    private static final long serialVersionUID = 1L;
    private String username;//必须与html标签中的名称一样,此处私有变量的值直接来自html标签对应名称填充过来的值
    private String password;//必须与html标签中的名称一样,此处私有变量的值直接来自html标签对应名称填充过来的值
    
    public LoginAction2(){
        System.out.println("构造方法LoginAction2 ......");
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    //调用业务层操作类的方法
    public String execute(){
        User u = new User();
        u.setUsername(this.getUsername());
        u.setPassword(this.getPassword());
        UserDao dao = new UserDao();
        if(dao.userLogin(u)){
            return "login_success";
        } else{
            return "login_failure";
        }
    }
}
第1个软件包net.nw.action创建LoginAction3动作类 :

package net.nw.action;
import com.opensymphony.xwork2.ActionSupport;
import net.nw.dao.UserDao;
import net.nw.vo.User;

public class LoginAction3 extends ActionSupport {
    
    /**
     * 对象序列化需要此serialVersionUID
     */
    private static final long serialVersionUID = 1L;
    private String username;//必须与html标签中的名称一样,此处私有变量的值直接来自html标签对应名称填充过来的值
    private String password;//必须与html标签中的名称一样,此处私有变量的值直接来自html标签对应名称填充过来的值
    
    public LoginAction3(){
        System.out.println("构造方法LoginAction3 ......");
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    //调用业务层操作类的方法
    public String execute(){
        User u = new User();
        u.setUsername(this.getUsername());
        u.setPassword(this.getPassword());
        UserDao dao = new UserDao();
        if(dao.userLogin(u)){
            return "login_success";
        } else{
            return "login_failure";
        }
    }
}

第1个软件包net.nw.action创建RegAction动作类 :

package net.nw.action;
import java.util.Date;
import com.opensymphony.xwork2.ActionSupport;
import net.nw.dao.UserDao;
import net.nw.vo.User;
public class RegAction extends ActionSupport {
    private static final long serialVersionUID = 1L;
    private User user;
    private String welcome="欢迎访问我的个人主页";
    private Date date = new Date();
    
    
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }
    public String getWelcome() {
        return welcome;
    }
    public void setWelcome(String welcome) {
        this.welcome = welcome;
    }
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
    public RegAction(){
        System.out.println("构造方法RegAction ......");
    }
    //调用业务层操作类的方法
    public String execute(){
        UserDao dao = new UserDao();
        if(dao.userLogin(user)){
            return "reg_success";
        } else{
            return "reg_failure";
        }
    }
    @Override
    public void validate() {
        // TODO Auto-generated method stub
        if(user.getUsername() ==null|| user.getUsername().trim().equals("")){
            this.addFieldError("username_error",this.getText("login.field.isnull",new String[]{this.getText("label.username")}));
            return;
        }
        if(user.getPassword() ==null|| user.getPassword().trim().equals("")){
            this.addFieldError("password_error",this.getText("login.field.isnull",new String[]{this.getText("label.password")}));
            return;
        }
        if(user.getPassword().length() < 4 || user.getPassword().length() > 6){
            this.addFieldError("password_error",this.getText("login.password.lengtherror"));
            return;
        }
        if(!user.getConfirmpass().equals(user.getPassword())){
            this.addFieldError("confirmpass_error",this.getText("login.confirmerror"));
            return;
        }
        super.validate();
    }
    
}

第1个软件包net.nw.action创建TestAction动作类 :

package net.nw.action;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport {

    private static final long serialVersionUID = 1L;
    private String xy;
    
    public String getXy() {
        return xy;
    }
    public void setXy(String xy) {
        this.xy = xy;
    }
    public TestAction(){
        System.out.println("构造方法TestAction ......");
    }
    public String add(){
        System.out.println("add()...");
        return "myAdd";
    }
    public String sayHello(){
        System.out.println("sayHello()...");
        return "mySayHello";
    }
    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }

}

第2个软件包包net.nw.dao创建UserDao操作类

package net.nw.dao;

import net.nw.vo.User;

//用户操作类
public class UserDao {

    public boolean userLogin(User u){
        
        if(!u.getUsername().equals("") && u.getPassword().equals("123456")){
            return true;
        } else {
            return false;
        }
    }
    
}

第3个软件包net.nw.servlet创建LoginServlet

package net.nw.servlet;

import Java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.nw.dao.UserDao;
import net.nw.vo.User;

/**
 * Servlet implementation class loginServlet
 */
public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request,response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        User u = new User();
        u.setUsername(request.getParameter("username"));
        u.setPassword(request.getParameter("password"));
        UserDao dao = new UserDao();
        if(dao.userLogin(u)){
            response.sendRedirect("login_success.jsp");
        }else{
            response.sendRedirect("login_failure.jsp");
        }
    }

}

第4个软件包net.nw.vo创建Education实体类

package net.nw.vo;
import java.util.ArrayList;
import java.util.List;
public class Education {
    private List<String> educations;
    public Education(){
        educations = new ArrayList<String>();
        this.educations.add("小学");
        this.educations.add("初中");
        this.educations.add("高中");
        this.educations.add("中专");
        this.educations.add("专科");
        this.educations.add("本科");
        this.educations.add("硕士");
        this.educations.add("博士");
    }
    public List<String> getEducations() {
        return educations;
    }
    public void setEducations(List<String> educations) {
        this.educations = educations;
    }

}

第4个软件包net.nw.vo创建Favorite实体类

package net.nw.vo;
import java.util.ArrayList;
import java.util.List;
public class Favorite {
    private List<String> favorites;
    
    public Favorite(){
        favorites = new ArrayList<String>();
        favorites.add("读书");
        favorites.add("上网");
        favorites.add("游戏");
        favorites.add("音乐");
        favorites.add("影视剧");
    }

    public List<String> getFavorites() {
        return favorites;
    }

    public void setFavorites(List<String> favorites) {
        this.favorites = favorites;
    }
}

第4个软件包net.nw.vo创建User实体类

package net.nw.vo;

//用户类
public class User {
    private String username;//用户名称
    private String password;//用户密码
    private String confirmpass;//确认密码
    private String gender;//性别
    private String education;//学历
    private String[] favorites;//爱好
    private String introduce;//自我介绍
    private boolean isAccept;//是否接受协议
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getConfirmpass() {
        return confirmpass;
    }
    public void setConfirmpass(String confirmpass) {
        this.confirmpass = confirmpass;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    public String getEducation() {
        return education;
    }
    public void setEducation(String education) {
        this.education = education;
    }
    public String[] getFavorites() {
        return favorites;
    }
    public void setFavorites(String[] favorites) {
        this.favorites = favorites;
    }
    public String getIntroduce() {
        return introduce;
    }
    public void setIntroduce(String introduce) {
        this.introduce = introduce;
    }
    public boolean getIsAccept() {
        return isAccept;
    }
    public void setIsAccept(boolean isAccept) {
        this.isAccept = isAccept;
    }

}

创建国际化资源文件App_en_US.properties

login.username=username:
login.password=password:
login.email=email:
login.submit=submit
login.username.isnull=username cannot be empty
login.password.isnull=password cannot be empty
login.email.isnull=email cannot be empty
login.password.lengtherror=password length is 4-6
login.email.formaterror=email format is error
login.field.isnull={0} cannot be empty
label.username=username
label.password=password
label.email=email
login.title=System login
label.registertitle=User Information
label.confirmpass=Confirm Password
login.confirmerror=Confirm password is not correct
label.gender=gender
label.education=Education
label.favorite=Favorite
label.introduce=Introduce myself
label.accept=whether to accept

创建国际化资源文件App_zh_CN.properties

login.username=\u7528\u6237\u540D\u79F0\uFF1A
login.password=\u7528\u6237\u5BC6\u7801\uFF1A
login.email=\u7535\u5B50\u90AE\u7BB1\uFF1A
login.submit=\u786E\u5B9A
login.username.isnull=\u7528\u6237\u4E0D\u80FD\u4E3A\u7A7A
login.password.isnull=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A
login.email.isnull=\u7535\u5B50\u90AE\u7BB1\u4E0D\u80FD\u4E3A\u7A7A
login.password.lengtherror=\u5BC6\u7801\u5FC5\u987B4-6\u4F4D
login.email.formaterror=\u7535\u5B50\u90AE\u7BB1\u683C\u5F0F\u4E0D\u6B63\u786E
login.field.isnull={0}\u4E0D\u80FD\u4E3A\u7A7A
label.username=\u7528\u6237\u540D\u79F0
label.password=\u7528\u6237\u5BC6\u7801
label.email=\u7535\u5B50\u90AE\u7BB1
login.title=\u7CFB\u7EDF\u767B\u5F55
label.registertitle=\u7528\u6237\u8D44\u6599
label.confirmpass=\u786E\u8BA4\u5BC6\u7801
login.confirmerror=\u786E\u8BA4\u5BC6\u7801\u4E0D\u6B63\u786E
label.gender=\u6027\u522B
label.education=\u5B66\u5386
label.favorite=\u7231\u597D
label.introduce=\u81EA\u6211\u4ECB\u7ECD
label.accept=\u662F\u5426\u63A5\u53D7\u534F\u8BAE

配置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.devMode" value="true" ></constant>
    <constant name="struts.i18n.encoding" value="utf-8" ></constant>
    <constant name="struts.custom.i18n.resources" value="App"></constant>
    <package name="default" namespace="/" extends="struts-default">
        <!-- action的name值必须等于LoginAction.java类命名规范(XxxxAction)中Xxxx,即是Login(首字母要小写) -->
        <action name="reg" class="net.nw.action.RegAction">
            <!-- result的name值必须等于LoginAction.java类里面被重写的execute方法的返回值 -->
            <result name="reg_success">/reg_success.jsp</result>
            <result name="reg_failure">/reg_failure.jsp</result>
            <result name="input">/register.jsp</result>
        </action>
        <action name="language">
            <result>/register.jsp</result>
        </action>
        <action name="test" class="net.nw.action.TestAction">
            <result name="success">/test/test.jsp</result>
            <result name="myAdd">/test/add.jsp</result>
            <result name="mySayHello">/test/say_hello.jsp</result>
        </action>
    </package>
</struts>

配置web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <welcome-file-list>
    <welcome-file>register.jsp</welcome-file>
  </welcome-file-list>
  <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>

</web-app>


test/add.jsp:

<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>Test.jsp</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  <body>
        <center>add.jsp页面</center>
  </body>
</html>

test/date.jsp:

<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<li>这里是一个包含静态页面</li>
<s:set value="date" var="mydate"/>
<s:date name="mydate" format="yyyy年MM月dd日 HH时mm分ss秒"/>

test/say_hello.jsp:

<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>Test.jsp</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  <body>
    <center>say_hello.jsp页面</center>
  </body>
</html>

test/test.jsp:

<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>Test.jsp</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  <body>
           <s:property value="#attr.xy" />
        <center>welcome to test.jsp</center>
  </body>
</html>


reg_failure.jsp:

<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>注册失败</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  <body>
    <center>
        <h1>注册失败</h1>
        <hr>
        <a href="<%=path%>/login.jsp">返回</a>
    </center>
  </body>
</html>

reg_success.jsp

<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title><s:property value="getText('login.title')"/></title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  <body>
    <center>
        <h1><s:property value="getText('label.registertitle')"/></h1>
        <hr>
        <s:label value="%{getText('label.username')}"/>:<s:property value="user.username"/><br>
        <s:label value="%{getText('label.password')}"/>:<s:property value="user.password"/><br>
        <s:label value="%{getText('label.gender')}"/>:<s:if test="user.gender==1">男</s:if><s:else>女</s:else><br>
        <s:label value="%{getText('label.education')}"/>:<s:property value="user.education"/><br>
        <s:label value="%{getText('label.favorite')}"/>:<s:property value="user.favorites"/><br>
        <s:label value="%{getText('label.introduce')}"/>:<s:property value="user.introduce"/><br>
        <s:label value="%{getText('label.accept')}"/>:<s:property value="user.isAccept"/><br>
        <br>
        <li>set标签的使用:<s:set value="welcome" var="VarWelcome"/><s:property value="#VarWelcome"/></li>
        <br>
        include标签使用(静态包含):<s:include value="test/date.jsp"/>
        <br>
        include标签使用(动态包含):<s:set var="includePage" value="%{'test/date.jsp'}"/>
        <s:include value="%{#includePage}"/>
        <br>
        <br>
        iterator标签使用(遍历数组类型):
        <s:iterator var="cities" value="{'北京','上海','深圳','武汉'}">
            <s:property />
        </s:iterator>
        
        <br>
        <br>
        iterator标签使用:<br>
        <s:iterator var="cities" value="{'北京','上海','深圳','武汉'}" status="status">
            <s:property />
            |已经遍历的记录的总数:<s:property value="#status.count"/>
            |当前记录的编号:<s:property value="#status.index"/>
            |是否是偶数:<s:property value="#status.even"/>
            |是否是奇数:<s:property value="#status.odd"/>
            |是否是第1条记录:<s:property value="#status.first"/>
            |是否是第最后一条记录:<s:property value="#status.last"/><br>
        </s:iterator>
        
        <br>
        <br>
        iterator标签使用(遍历map类型):<br>
        <s:iterator var="stus" value="#{'zhangsan':'张三','lisi':'李四','wangwu':'王五','zhaoliu':'赵六'}">
            <s:property value="#stus.key" /> = <s:property value="#stus.value" /><br>
        </s:iterator>
        
        <br>
        <br>
        action标签的使用:<s:action name="test" executeResult="true" ignoreContextParams="true">
        this is a testing<br>
            <s:param name="xy" value="%{'传递参数值,必须在action动作类里定义参数名称name对应的set,get属性'}"></s:param>
        </s:action>
        <br>
        
        <br>
        <br>
        action标签的使用:<s:action name="test!add" executeResult="true">测试test</s:action>
        <br>
        
        <br>
        <br>
        action标签的使用:<s:action name="test!sayHello" executeResult="true">测试test</s:action>
        <br>
        
        <s:debug></s:debug>
    </center>
  </body>
</html>
register.jsp:

<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title><s:property value="getText('login.title')"/></title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <script type="text/javascript">
        function init(){
            document.getElementById("username").value="";
            document.getElementById("username").style.color="#000000";
        }
    </script>
  </head>
  <body>
        <center>
        <pre>
            <a href="<%=path%>/language.action?request_locale=en_US">English</a> <a href="<%=path%>/language.action?request_locale=zh_CN">Simplified Chinese</a>
        </pre>
        <h1><s:property value="getText('login.title')"/></h1>
        <hr>
        <s:fielderror cssStyle="color:red"></s:fielderror>
        <s:form name="regForm" action="reg" method="post">
            <s:bean name="net.nw.vo.User" var="u">
                <s:param name="username" value="%{'请输入用户名称'}" />
            </s:bean>
            <s:bean name="net.nw.vo.Education" var="eduList"/>
            <s:bean name="net.nw.vo.Favorite" var="favList"/>
            <s:textfield label="%{getText('label.username')}" name="user.username" required="true" id="username" cssStyle="color:#cbcbcb" value="%{#u.username}" onclick="init()"/>
            <s:textfield label="%{getText('label.password')}" name="user.password" required="true"/>
            <s:textfield label="%{getText('label.confirmpass')}" name="user.confirmpass" required="true"/>
            <s:radio label="%{getText('label.gender')}" name = "user.gender" list="#{'1':'男','0':'女'}" value="1"/>
            <s:select label="%{getText('label.education')}" name="user.education" list="%{#eduList.educations}"  headerKey="" headerValue="--请选择--"/>
            <s:checkboxlist label="%{getText('label.favorite')}" name="user.favorites" list="%{#favList.favorites}"  />
            <s:textarea label="%{getText('label.introduce')}" name="user.introduce" rows="10" cols="50"/>
            <s:checkbox label="%{getText('label.accept')}" name="user.isAccept" />
            
            <s:submit value="%{getText('login.submit')}" />
        </s:form>
        <s:debug></s:debug>
    </center>
  </body>
</html>
解决Tomcat传递中文参数值出现乱码,修改默认的Tomcat配置server.xml

 <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"URIEncoding="UTF-8"/>

测试效果截图如下:
   

本项目源码下载地址:
0 0
原创粉丝点击