struts2标签s:text name=“”/问题小结

发布时间:2024-12-04 21:30

注意防伪标签的完整性:破损或模糊的防伪标签可能有问题。 #生活知识# #购物技巧# #品牌鉴别方法#

最新推荐文章于 2022-02-13 17:15:22 发布

anhuixiaozi 于 2010-10-08 20:55:00 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

问题点:

为什么用以下代码:
<td width="5%">
  <s:text name="studentPage.student.studentName"/>
</td>
<td class="bj" width="20%">
${studentPage.student.teacher.teacherName }
</td>
可以输出:“学生姓名:张老师”
而用:
<td width="5%">
  <s:text name="studentPage.student.teacher.teacherName "/>
</td>
<td class="bj" width="20%">
${studentPage.student.teacher.teacherName }
</td>
却输出:“studentPage.student.teacher.teacherName :张老师”
而不是:“老师姓名:张老师”

解决方案:

1)环境,jdk1.5,tomcat5.5
2)struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.custom.i18n.resources" value="globalMessages"/>
<package name="anhuixiao" namespace="/anhuixiao" extends="struts-default">
<action name="studentshow" class="cn.anhuixiao.action.StudentShowAction">
<result name="show">/WEB-INF/page/studentShow.jsp</result>
</action>
</package>
</struts>
3)StudentShowAction.java
package cn.anhuixiao.action;

import cn.anhuixiao.bean.Student;
import cn.anhuixiao.bean.StudentPage;

public class StudentShowAction {

private StudentPage studentPage;

public StudentPage getStudentPage() {

return studentPage;
}

public void setStudentPage(StudentPage studentPage) {
this.studentPage = studentPage;
}

public String execute() {
studentPage = new StudentPage();
Student student = new Student();
student.setStudentName("anhuixiao");
studentPage.setStudent(student);
return "show";
}
}
4)Student.java
package cn.anhuixiao.bean;

public class Student {

private String studentName;

public Student(){

}
public String getStudentName() {
return studentName;
}

public void setStudentName(String studentName) {
this.studentName = studentName;
}
}
5)StudentPage.java
package cn.anhuixiao.bean;

public class StudentPage {

private Student student;

public StudentPage(){

}
public Student getStudent() {
return student;
}

public void setStudent(Student student) {
this.student = student;
}
}
6)globalMessages_zh_CN.properties
studentPage.student.studentName=anhuixiao
7)studentShow.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>My JSP 'personlist.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"> 

  </head>

     <body>
  EL表达式输出Action中studentPage.student.studentName内容:
  ${studentPage.student.studentName}<br/>

     stuts2标签输出Action中studentPage.student.studentName内容:
  <s:property value="studentPage.student.studentName"/><br/>
  s:textfield输出Action中studentPage.student.studentName内容:
  <s:textfield name="studentPage.student.studentName"/><br/>
  s:text输出globalMessages_zh_CN.properties中 studentPage.student.studentName内容:
  <s:text name="studentPage.student.studentName"/>
  </body>
</html>

说明:
1)<s:textfield />对应html中的<input type=text/>
2) <s:text />对应html中的<label>,struts2主要用它读资源文件

3)如果配置在struts.xml中一定要有<constant name="struts.custom.i18n.resources" value="globalMessages"/>
4)如果配置在stuts.properties中一定要有 struts.custom.i18n.resources=globalMessages

网址:struts2标签s:text name=“”/问题小结 https://www.yuejiaxmz.com/news/view/376783

相关内容

HTMl综合各大网站谈谈Meta标签和meta property=og标签含义
input标签的type为select、radio、checkbox的使用
mata name,property='og:title
【HTML】表单标签,表单的格式化
软件开发实训(720科技)――第五课:数据绑定和标签库
thisname != null && thisname.equals(name);
dwr.xml配置(allow标签
html a标签属性 rel='nofollow'
定制自己的windows terminal。支持分屏多标签页的生产力工具?
360浏览器 兼容模式下页面显示异常(出现不改出现的HTML标签)

随便看看