问题描述
感谢您的宝贵时间.我正在上课上的家庭作业,但陷入了困境.我对JSP不太熟悉,这是我使用JSP的第一周,所以我不确定如何解决此问题.如何获得x:out select ="来接受变量?例如,我想要的是:
Thanks for your time. I am working on my homework for class and have gotten myself stuck. I'm not very familiar with JSP and this is my first week working with it so I'm not sure how to fix this problem. How do I get x:out select="" to accept a variable? For instance what I want is:
<x:out select="$output/stores/store[${x}]/name" /> <br>
错误是属性选择不接受任何表达式".我的问题是我该如何解决?我的目标是创建一个循环,循环遍历我正在加载的所有XML.
The error is "attribute select does not accept any expressions". My question is how can I work around this? My goal is to create a loop that cycles through all of the XML I'm loading.
还有人知道如何获取xml文件中的元素数量吗?我注意到在我正在加载的XML中,有一些变量叫做="6" total total ="6",我只是不知道如何访问它们.
Also does anyone know how to get the number of elements in an xml file? I noticed in the XML I'm loading there are variables called to="6" total total="6" I just don't know how to access them.
如果需要的话,下面是我的完整代码.
Below is my full code if you need it.
谢谢,汤米
<%--
Document : newjsp
Created on : Nov 30, 2013, 8:41:46 AM
Author : c8k
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="javax.xml.parsers.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<c:import var="stores" url="http://api.remix.bestbuy.com/v1/stores(area(${param.zip},${param.dist}))?show=storeId,name,distance,lat,lng&apiKey=fuzgmrj4nv8v9ummatn78m3k"/>
<x:parse xml="${stores}" var="output"/>
<b>The first stores information is:</b> <br>
<%!
boolean b = true;
int x = 1;
%>
<x:out select="$output/stores/store[${x}]/storeId" /> <br>
<x:out select="$output/stores/store[1]/name" /> <br>
<x:out select="$output/stores/store[1]/distance" /> <br>
<x:out select="$output/stores/store[1]/lat" /> <br>
<x:out select="$output/stores/store[1]/lng" /> <br>
</body>
</html>
推荐答案
更改<%@ taglib前缀="c" uri ="http://java.sun.com/jstl/core"%>不正确为我.对于我的项目(web-app version ="3.0")IDE(MyEclipse),我看到x.tld的配置文件.select的错误之处在于不允许选择外观$ {}或<%=%>因此,我有办法在web.xml中作弊.
change <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> is not right for me. for my project(web-app version="3.0" ) IDE(MyEclipse) I see the configuration file of x.tld.There is the false of select which do not allow the select apperance ${} or <%=%>.So I got a way to cheat in the web.xml.
1. <jsp-config> <taglib> <taglib-uri>/huang</taglib-uri> <taglib-location>/WEB-INF/x.tld</taglib-location> </taglib> </jsp-config>
1.<jsp-config> <taglib> <taglib-uri>/huang</taglib-uri> <taglib-location>/WEB-INF/x.tld</taglib-location> </taglib> </jsp-config>
添加到web.xml
add to web.xml
2.像这样在我的jsp文件中声明新的taglib-url名称"huang":
2.declare the new taglib-url name "huang" to my jsp file like this:
<%@ taglib prefix="x" uri="/huang" %>
3.使用<x:out select="$casexml//案例//${node.name }" />
我可以得到正确的结果
这篇关于< x:out select ="" />不接受变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!