我正在尝试为我的字符串列表中的每个字符串生成一个链接。此链接将调用操作并传入参数(传入studentId的getStudentById操作)。我已经尝试了几种方法来通过搜索互联网来实现这一点,但是,没有任何运气。最近的尝试导致每个链接都有一个“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>
答案 0 :(得分:0)
而不是:
<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} vs%{#url}