在 struts2 中使用 s:url 在 s:a 中
Using s:url in s:a in struts2
我正在尝试为我的字符串列表中的每个字符串生成一个 link。这个 link 将调用一个动作并传入一个参数(传入 studentId 的 getStudentById 动作)。我已经尝试了几种方法来通过在互联网上搜索来使它起作用,但是,没有任何运气。最近的尝试结果是每个 link 都有一个 url 的 "www.com",我不知道这是从哪里来的。下面是一些文件,可以帮助我找出问题所在。
WinnerAcknowledgement.jsp
<!DOCTYPE html>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/js/jquery/jquery-ui-1.11.4/jquery-ui.css" type="text/css" media="all"/>
<link rel="stylesheet" href="${pageContext.request.contextPath}/js/jquery/jquery-ui-1.11.4/jquery-ui.theme.css" type="text/css" media="all"/>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap/bootstrap-datepicker.css" type="text/css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/survey_bh.css" type="text/css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style_bh.css" type="text/css" />
</head>
<body>
<a href='index.jsp'>Home</a>
<p>Survey saved!</p>
<p>Congratulations! You're the winner of the raffle and have just won two movie tickets.</p>
<div>
<s:set var="mean" value="db.mean"/>
<s:set var="standardDeviation" value="db.standardDeviation"/>
<p><span><strong>Mean:</strong></span> <span><s:number name="%{mean}" type="number" /></span></p>
<p><span><strong>Standard Deviation:</strong></span> <span><s:number name="%{standardDeviation}" type="number" /></span></p>
</div>
<div>
<p>Students:</p>
<ul>
<s:iterator value="studentIds" status="status">
<s:url action="getStudentById" includeParams="get" var="url">
<s:param name="studentId"><s:property/></s:param>
</s:url>
<li>
<s:a href="%{url}"><s:property/></s:a>
</li>
</s:iterator>
</ul>
</div>
</body>
</html>
struts.xml
<!--?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.enable.DynamicMethodInvocation" value="false"></constant>
<constant name="struts.devMode" value="false"></constant>
<constant name="struts.custom.i18n.resources" value="ApplicationResources"></constant>
<package name="default" extends="struts-default" namespace="/">
<action name="getStudentById" class="com.action.SurveyAction" method="getStudentById">
<result name="success">Student.jsp</result>
<result name="error">NoSuchStudent.jsp</result>
</action>
<action name="saveSurvey" class="com.action.SurveyAction" method="saveSurvey">
<result name="simple">SimpleAcknowledgement.jsp</result>
<result name="winner">WinnerAcknowledgement.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>
</struts>
而不是:
<s:iterator value="studentIds" status="status">
<s:url action="getStudentById" includeParams="get" var="url">
<s:param name="studentId"><s:property/></s:param>
</s:url>
<li>
<s:a href="%{url}"><s:property/></s:a>
</li>
</s:iterator>
我刚刚试过了,它成功了:
<s:iterator value="studentIds" status="status">
<s:url action="getStudentById" includeParams="get" var="url">
<s:param name="studentId"><s:property/></s:param>
</s:url>
<li>
<s:a href="%{#url}"><s:property/></s:a>
</li>
</s:iterator>
区别是 %{url} 与 %{#url}
我正在尝试为我的字符串列表中的每个字符串生成一个 link。这个 link 将调用一个动作并传入一个参数(传入 studentId 的 getStudentById 动作)。我已经尝试了几种方法来通过在互联网上搜索来使它起作用,但是,没有任何运气。最近的尝试结果是每个 link 都有一个 url 的 "www.com",我不知道这是从哪里来的。下面是一些文件,可以帮助我找出问题所在。
WinnerAcknowledgement.jsp
<!DOCTYPE html>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/js/jquery/jquery-ui-1.11.4/jquery-ui.css" type="text/css" media="all"/>
<link rel="stylesheet" href="${pageContext.request.contextPath}/js/jquery/jquery-ui-1.11.4/jquery-ui.theme.css" type="text/css" media="all"/>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap/bootstrap-datepicker.css" type="text/css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/survey_bh.css" type="text/css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style_bh.css" type="text/css" />
</head>
<body>
<a href='index.jsp'>Home</a>
<p>Survey saved!</p>
<p>Congratulations! You're the winner of the raffle and have just won two movie tickets.</p>
<div>
<s:set var="mean" value="db.mean"/>
<s:set var="standardDeviation" value="db.standardDeviation"/>
<p><span><strong>Mean:</strong></span> <span><s:number name="%{mean}" type="number" /></span></p>
<p><span><strong>Standard Deviation:</strong></span> <span><s:number name="%{standardDeviation}" type="number" /></span></p>
</div>
<div>
<p>Students:</p>
<ul>
<s:iterator value="studentIds" status="status">
<s:url action="getStudentById" includeParams="get" var="url">
<s:param name="studentId"><s:property/></s:param>
</s:url>
<li>
<s:a href="%{url}"><s:property/></s:a>
</li>
</s:iterator>
</ul>
</div>
</body>
</html>
struts.xml
<!--?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.enable.DynamicMethodInvocation" value="false"></constant>
<constant name="struts.devMode" value="false"></constant>
<constant name="struts.custom.i18n.resources" value="ApplicationResources"></constant>
<package name="default" extends="struts-default" namespace="/">
<action name="getStudentById" class="com.action.SurveyAction" method="getStudentById">
<result name="success">Student.jsp</result>
<result name="error">NoSuchStudent.jsp</result>
</action>
<action name="saveSurvey" class="com.action.SurveyAction" method="saveSurvey">
<result name="simple">SimpleAcknowledgement.jsp</result>
<result name="winner">WinnerAcknowledgement.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>
</struts>
而不是:
<s:iterator value="studentIds" status="status">
<s:url action="getStudentById" includeParams="get" var="url">
<s:param name="studentId"><s:property/></s:param>
</s:url>
<li>
<s:a href="%{url}"><s:property/></s:a>
</li>
</s:iterator>
我刚刚试过了,它成功了:
<s:iterator value="studentIds" status="status">
<s:url action="getStudentById" includeParams="get" var="url">
<s:param name="studentId"><s:property/></s:param>
</s:url>
<li>
<s:a href="%{#url}"><s:property/></s:a>
</li>
</s:iterator>
区别是 %{url} 与 %{#url}