见鬼,Structs2 domain方式无法接受参数

xx314327475 2010-07-23 12:27:38
每分了 分押宝全输了 各位海涵


<!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=UTF-8">
<title>CharactorEncoding</title>
<base href="http://localhost:8080/Structs2_001_domainModel/">
<!-- 注意这里的地址 -->
</head>
<body>
使用domainModel方法来保存参数
<a href="Char/DomainModel!add?user.name=lee&user.age=23">测试</a>
</body>
</html>



....
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/Char" extends="struts-default">
<action name="DomainModel" class="com.lee.structs.UserAction">
<result>
/Test.jsp
</result>

</action>
</package>
....



package com.lee.structs;
import com.opensymphony.xwork2.ActionSupport;
import com.lee.structs.User;

public class UserAction extends ActionSupport {

private User user;

public String add() {
System.out.println("name= " + user.getName());
System.out.println("age= " + user.getAge());
return "success";

}

}



package com.lee.structs;

public class User {
private String name;
private int age;

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}


}


DomainModel!add?user.name=lee&user.age=23
通过此超链接调用DomainModel这个action中类的add方法,并且将name和age属性传给User.java,最后将name和age的值打到服务器上.

哪里有错...
...全文
42 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yousite1 2010-07-23
  • 打赏
  • 举报
回复
package com.lee.structs;
import com.opensymphony.xwork2.ActionSupport;
import com.lee.structs.User;

public class UserAction extends ActionSupport {

private User user;

public String add() {
System.out.println("name= " + user.getName());
System.out.println("age= " + user.getAge());
return "success";

}

}
你没生成user的getter和setter代码呀。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧