今天做struts2的集合类型转换时出了些无法理解的问题:
想做一个发布新闻的一个页面,然后用另一个页面来显示,输入页面可以显示,显示页面却出了问题,,不显示输入的信息,值栈也是空的。
struts.xml
<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="TestList" extends="struts-default">
<action name="Text" class="zq.SubmitAction">
<result name="success">/showlist.jsp</result>
<result name="input">/List.jsp</result>
</action>
</package>
</struts>
输入页面 List.jsp
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<s:head/>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<table>
<s:form id="newsform" action="Text" theme="simple">
<table>
<tr>
<td>标题</td>
<td>内容</td>
<td>时间</td>
</tr>
<s:iterator value="new int[3]" status="m">
<tr>
<td><s:textfield name="%{'newsList.['+#m.index'].title'}"/></td>
<td><s:textfield name="%{'newsList.['+#m.index'].content'}"/></td>
<td><s:datetimepicker name="%{'newsList.['+#m.index'].riqi'}"></s:datetimepicker></td>
</tr>
</s:iterator>
<tr>
<td colspan="3"><s:submit value="提交"></s:submit></td>
</tr>
</table>
</s:form>
</table>
</body>
</html>
显示页面 showlist.jsp
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td>标题</td>
<td>内容</td>
<td>时间</td>
</tr>
<s:iterator value="newsList" status="m">
<tr>
<td><s:property value="title"/></td>
<td><s:property value="content"/></td>
<td><s:property value="riqi"/></td>
</tr>
</s:iterator>
</table>
<s:debug/>
</body>
</html>
javaBean News.java
package zq;
import java.util.Date;
public class News {
public String title;
public String content;
public Date riqi;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getRiqi() {
return riqi;
}
public void setRiqi(Date riqi) {
this.riqi = riqi;
}
}
Action SubmitAction.java
package zq;
import java.util.*;
import com.opensymphony.xwork2.ActionSupport;
public class SubmitAction extends ActionSupport {
public List<News> newsList;
public List<News> getNewsList() {
return newsList;
}
public void setNewsList(List<News> newsList) {
this.newsList = newsList;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return "success";
}
}
局部转换文件 SubmitAction-conversion.properties
Element_newsList=zq.News
现在SubmitAction.java与News.java和SubmitAction-conversion.properties都在zq目录下,可是showlist.jsp就是不显示内容。而且值栈为空,我正在解决中,希望高手看到的话给我些提示,谢谢。。。
分享到:
相关推荐
struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换
struts2四天的学习笔记。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
NULL 博文链接:https://zhaolianyang.iteye.com/blog/859890
struts2学习笔记,非本人所写,但有学习的价值,总结的很好,分享一个!
这是学习struts2时记得重点笔记,包括了一些原理,ognl语句的编写,以及如何设置拦截器等等一些基本知识,起到复习和巩固的作用
struts2学习笔记总结
Struts2学习笔记,介绍了struts2的基础部分
struts2.1数据类型转换2struts2.1数据类型转换2struts2.1数据类型转换2struts2.1数据类型转换2struts2.1数据类型转换2struts2.1数据类型转换2struts2.1数据类型转换2struts2.1数据类型转换2
关于struts2的类型转换的处理方法。
struts2的类型转换详解struts2的类型转换详解
Struts2处理类型转换错误,全局处理,如处理时间转换错误
使用struts2提供的转化器,实现Date类型的数据转换
1. struts2框架的引入 1)把struts2的相关jar包导入到项目中去 2)把struts2框架的配置文件struts.xml复制粘贴到项目中的src下面(同时也可以把log4j.properties放到src下) 在这里我们主要是要的这个struts.xml文件...
Struts2自定义类型转换
struts2数据类型转换
struts2学习笔记struts2学习笔记struts2学习笔记
struts2 将要进行自定义类型转换的点数据从1个增加到3个 struts3 进行全局的类型转换 struts4 使用Struts2中内部类中的方法进行自定义类型转换,用到的类StrutsTypeConverter struts5 增加集合类型,使用范型 ...
NULL 博文链接:https://hanazawakana.iteye.com/blog/1681564
学习Struts2第三天笔记