struts2标签在jsp页面取不到值,新手求学,老手赐教

shan4260 shan4260 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题情况:设置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 {

/**
*
*/
private static final long serialVersionUID = 1L;
private MessageStore messageStore;
public String excute() throws Exception{
messageStore=new MessageStore();
//this.setMessageStore(msg);
return SUCCESS;
}
public MessageStore getMessageStore() {
return messageStore;
}

public void setMessageStore(MessageStore messageStore) {
this.messageStore = messageStore;
}
}


struts.config:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.devMode" value="true" />

<package name="basicstruts2" extends="struts-default">

<action name="index">
<result>/index.jsp</result>
</action>
<action name="hello" class="helloaction.HelloWorldAction" method="excute" >
<result>/HelloWorld.jsp</result>
</action>
</package>
</struts>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Basic_Struts2_Ant</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>



其中红色部分是我想获得字符串“Hello,Struts user!"的地方,但是只显示默认的no value,鼓捣3天了,请给个明白的解释吧,谢谢
...全文

相关推荐

struts2 标签使用

在 Struts2 中,`<s:if>` 标签是一种常用的条件判断标签,用于在页面上根据不同的条件展示不同的内容。

jl58585588

Struts框架中<s:bean>标签的使用方法

Struts框架作为Java EE应用中的一项重要技术,其历史可以追溯到2001年,由Craig McClanahan开发,并随后成为了Apache软件基金会的一个项目。Struts 1框架在早期的Web开发中广泛应用,为开发者提供了一种更为模块化和易于管理的方式来构建MVC(Model-View-Controller)架构的Web应用程序。随着时间的推移,Struts框架经历了多个版本的迭代,每个新版本都致力于解决之前版本中的问题,提升性能和安全性,并且引入新的特性以适应不断变化的Web开发需求。

loretta bu

struts2 OGNL之&lt;s:property&gt;标签访问值栈(value stack)用法

在Struts2中,OGNL被广泛用于视图层,允许开发者直接在JSP页面上访问模型数据。`<s:property>`标签是Struts2标签库的一部分,它用于显示值栈上的对象属性值。1.

jiajia333666

jsp中struts2.0标签应用示例

总结来说,"jsp中struts2.0标签应用示例"这个主题主要关注如何在JSP页面中利用Struts2.0提供的标签进行视图层的构建,通过实际例子展示了`<s:form>`、`<s:textfield

wlzhaogongzuo

struts2<s:if>使用心得

Struts2的核心组件之一便是它的标签库,包括但不限于表单标签、条件标签等。### `<s:if>`标签详解`<s:if>`标签用于根据特定条件执行不同的HTML或JSP代码块。

jiaqianhero
评论 10
收藏 已收藏
分享
返回顶部
shan4260
Web 开发 81,108 成员 341,721 内容