Error setting expression 'ly1.content' with value '[Ljava.lang.String;@486d6c53' ognl.OgnlException:

源代码

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>留言板</title>
</head>
<body bgcolor="e3e3e3">
<s:form action="add" meth="post" theme="simple">
<table border="11">
<caption>填写留言信息</caption>
<tr>
<td>留言标题</td>
<td><s:textfield name="ly1.title" /></td>
</tr>
<tr>
<td>留言内容</td>
<td><s:textarea name="ly1.content"  rows="5" cols="35"/></td>
</tr>
</table>
<input type="submit" value="提交">
<input type="reset" value="重置">
</s:form>
</body>
</html>

package org.action;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Map;

import org.model.UserTable;
import org.model.lyTable;
import org.work.SqlSrvDBConn;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class AddAction extends ActionSupport{
	private lyTable ly1;
	public lyTable getLytable() {
		return ly1;
	}

	public void setLytable(lyTable ly1) {
		this.ly1 = ly1;
	}

	public String execute() throws Exception{
		System.out.println("--------");
		String title=ly1.getTitle();
		System.out.println("title:" + title);
		String content=ly1.getContent();
		ActionContext context=ActionContext.getContext();
		//获得会话对象,用来保存当前登录用户的信息。
		Map session=context.getSession();
		UserTable user=(UserTable) session.get("user");
		lyTable ly=new lyTable();
		ly.setUserId(user.getId());
		ly.setDate(new Date(System.currentTimeMillis()));//获取时间
		ly.setTitle(title);//将标题存入ly
		ly.setContent(content);//将内容存入ly
		ArrayList al=(ArrayList)session.get("al");
		al.add(ly);
		/*PreparedStatement psmt=null;*/
		SqlSrvDBConn sqlsrv=new SqlSrvDBConn();
		/*Connection ct=sqlsrv.getConn();*/
		/*try {
			//在lyTable中插入值
			psmt=ct.prepareStatement("insert into lyTable(userId,date,title,content) values(?,?,?,?)");
		 
			psmt.setInt(1, ly.getUserId());
		    psmt.setInt(2, ly.getUserId());
		    psmt.setDate(2, ly.getDate());
		    psmt.setString(3, ly.getTitle());
		    psmt.setString(4, ly.getContent());
		    psmt.executeUpdate();
		    return "main";
		} catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
			return "liuyan";
		}*/
		if(sqlsrv.save(ly)){
			return "main";
		}
		else{
			return "error";
		}
	}
	

}

如果把

<td><s:textfield name="ly1.title" /></td>
</tr>
<tr>
<td>留言内容</td>

<td><s:textarea name="ly1.content" rows="5" cols="35"/></td>

中的name属性ly1.content改成lytable.content就没有问题

如果有大神路过帮忙看下是不是因为数字的原因。域模型中的分装不能封装到带数字的标签中么?

小白提问~

猜你喜欢

转载自blog.csdn.net/v_nbsp/article/details/80405174
今日推荐