我开发了一个简单的Struts 2项目。但是当我尝试从valuestack中检索数据时,我没有得到任何数据。在获取服务页面时,无法识别%{}语法。
我的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>
<form method="get" action="justwork.action">
<input type="text" name="name" value="Xarvis">
<input type="submit" >
</form>
</body>
</html>
我的struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<package name="TestFramework" extends="struts-default" >
<action name="justwork" class="org.pranab.actions.OGNLTest">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
我的OGNLTest.java
package org.pranab.actions;
import com.opensymphony.xwork2.ActionContext;
public class OGNLTest {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute(){
return "success";
}}
最后我的成功.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>
<h2>SUCCESS</h2>
<s:property default="%{name}" value="name"/>
<br>
%{name}
</body>
</html>
提交时的输出:
是否需要在strust.xml或属性中使用开关来启用%{}语法?
答案 0 :(得分:0)
你混淆了:
%{}
是OGNL's expression evaluation operator。${}
,which is JSP EL default
attribute is of type String,而不是value
之类的对象,因此无法对其进行评估。
在其中放入一个静态字符串。