为什么s:property不显示内容

Zh.晨光
前端领域优质创作者
博客专家认证
2014-11-11 10:05:01

package tutorial;
import com.opensymphony.xwork2.ActionSupport;
//第一个Struts Action类直接继承ActionSupport
public class HelloReader extends ActionSupport{
public static final String MESSAGE="Hello Reader!I'm from Struts2";
//struts2将调用此方法,如果在配置文件中未指定execute()方法为默认方法;
public String execute()throws Exception{
setMessage(MESSAGE);
return SUCCESS;
}
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
//唯一的属性,将被自动赋值并打印
private String message;
}


//=========
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="tutorial" extends="struts-default">
<action name="HelloReader" class="tutorial.HelloReader">
<result>/helloreader.jsp</result>
</action>
<!-- 添加actions到这里 -->
</package>
</struts>


//===========
...全文
306 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zh.晨光 2014-11-11
  • 打赏
  • 举报
回复
貌似,jsp没有调用struts.xml的数据
Lucky_fishy 2014-11-11
  • 打赏
  • 举报
回复
<s:debug>一下,看值有没有传到页面上
Zh.晨光 2014-11-11
  • 打赏
  • 举报
回复
看着没错,为什么不显示出来值呢?
shixitong 2014-11-11
  • 打赏
  • 举报
回复
后台action还进入了
Zh.晨光 2014-11-11
  • 打赏
  • 举报
回复
<%@taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>hello Reader!</title> </head> <body> <!-- 使用property标签来获取Action中的属性,直接显示在页面中 --> <s:property value="message"/>fdf </body> </html>
shixitong 2014-11-11
  • 打赏
  • 举报
回复
你前台怎么写的,绝对是可以显示 1、引入struts2标签 <%@ taglib prefix="s" uri="/struts-tags" %> 2、取值 <s:property value="message"/>

67,513

社区成员

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

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