Using s: url in s: a in struts2

I am trying to create a link for every line in my list of lines. This link will call the action and pass the parameter (the getStudentById action passing in studentId). I've tried several ways to get this to work by looking in interwebs, however no luck. The most recent attempt results in each link having a "www.com" URL, which I don't know where this is coming from. Below are a few files to consider trying to help me figure out what's going wrong.

WinnerAcknowledgment.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>&nbsp;&nbsp;<span><s:number name="%{mean}" type="number" /></span></p>
            <p><span><strong>Standard Deviation:</strong></span>&nbsp;&nbsp;<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>

      

+3


source to share


1 answer


Instead:

<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>

      

I just tried this and it worked:



<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>

      

The difference is that% {url} vs% {# url}

0


source







All Articles