【问题标题】:Passing parameters between jsp and xsljsp和xsl之间传递参数
【发布时间】:2016-01-05 23:29:15
【问题描述】:

我的 jsp 页面和 xsl 之间有问题,我想在 jsp 和 xsl 之间传递一个参数,但它从未在 xsl 中设置。

JSP 页面;

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
<%!
    private String getVal(String param, HttpServletRequest request) {
        return request.getParameter("fname");
    }
%>
<%
    String num = getVal("value", request);
%>

<div id="section" class="col-xs-10 col-sm-10 col-md-8">
            <c:import url="/monXml.xml" var="inputDoc" />

            <c:import url="/viewAnnonce.xsl" var="stylesheet" />
            <x:transform xml="${inputDoc}" xslt="${stylesheet}" >
                 <x:param name="numAnnonce" value="${num}"/>
            </x:transform>

        </div>

XSL:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="utf-8"
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />

  <xsl:param name="numAnnonce"/>

 <xsl:template match="/">
    <xsl:template match="/">
        <!-- Creation de la liste des annonces -->
        <xsl:for-each select=".//annonce[attribute::id=$numAnnonce]">
            <div id="article" class="row"></div>
        </xsl:for-each>
 </xsl:template>

`

getVal("value", request);返回正确的值。

谢谢。

【问题讨论】:

    标签: java xml jsp xslt


    【解决方案1】:

    您已经使用 JSP scriptlet 声明了您的 num 变量, 我认为您无法使用 ${num} 访问它,您可以尝试使用 scriptlet 访问它吗:

    <x:param name="numAnnonce" value="<%=num%>"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多