[英]Struts 2 - Cannot display value from Action in JSP Page
我是新手,正在使用Struts2。我花了幾天時間,但無法修復它。
動作類:
public class UserAction extends ActionSupport implements Action{
private static final long serialVersionUID = 3665293407194339009L;
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
message="this is inside execute";
return SUCCESS;
}
}
在struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value="html" />
<package name="default" namespace="/" extends="struts-default">
<action name="index" class="com.action.controller.UserAction" method="execute">
<result name="SUCCESS">/index.jsp</result>
</action>
</package>
</struts>
的index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!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>Insert title here</title>
</head>
<body>
<h4>AAAAA</h4>
<s:property value="message"/>
</body>
</html>
它僅在<h4>
顯示AAAA,但不顯示該消息。 我同時嘗試了XML和注釋,但未顯示該消息。 我不知道我的項目出了什么問題。
您將返回映射到字符串"success"
的常量SUCCESS
,然后在struts.xml中映射字符串"SUCCESS"
。
在struts.xml中將"SUCCESS"
更改為"success"
:
<result name="success">/index.jsp</result>
您可能沒有經過操作就打開頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.