`
夜之son
  • 浏览: 25820 次
  • 性别: Icon_minigender_1
  • 来自: 信阳
社区版块
存档分类
最新评论

struts2集合类型转换学习笔记1

阅读更多

今天做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.javaNews.javaSubmitAction-conversion.properties都在zq目录下,可是showlist.jsp就是不显示内容。而且值栈为空,我正在解决中,希望高手看到的话给我些提示,谢谢。。。

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics