日期:2014-05-17  浏览次数:20664 次

struts2标签<s:property>在jsp页面取不到值,新手求学,老手赐教
问题情况:设置struts框架后,建立index.jsp页面,HelloWorldAction.java,MessageStore.java,
我想通过index页面请求action获取MessageStore.java中的message的值然后输出到HelloWorld页面,但是<s:property value="messageStore.message" default="no value"/>后value没获取值。
全部代码和主要设置如下:
index .jsp
<%@page import="com.opensymphony.xwork2.util.*" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<!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=ISO-8859-1">
<title>Basic Struts 2 Application - Welcome</title>
</head>
<body>
<h1>Welcome To Struts 2!</h1>
<p><a href="<s:url action='hello'/>">Hello World</a></p>
</body>
</html>



HelloWorld.jsp:

<%@page import="com.opensymphony.xwork2.util.*" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<!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=ISO-8859-1">
<title>Hello World!</title>
</head>
<body>
    <h2><s:property value="messageStore.message" default="no value"/></h2>
 <%%>
</body>
</html>



MessageStore.java:


package hellomodel;

public class MessageStore {
private String message;
public MessageStore(){
setMessage("Hello,Struts user!");
}
public void setMessage(String message){
this.message=message;
}
public String getMesssage(){
return message;
}

}


HelloWorldAction.java:


package helloaction;
import hellomodel.MessageStore;
import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldAction extends ActionSupport {

/**
 * 
 */