【发布时间】:2013-12-05 00:02:31
【问题描述】:
对于数据库中的每个所有者,我需要 Web 应用程序的用户能够单击不同的按钮来加载不同的信息。例如,下面的代码是一个jsp,其中用户在左侧选择了一个所有者,它在右侧加载了所选所有者sel_owner的详细信息。然后是 sel_owner 的三个按钮,一个显示 sel_owner 拥有的猫,另一个显示 sel_owner 拥有的狗,第三个显示 sel_owner 拥有的所有宠物。工具代码涉及三个按钮中的 url 模式和三个 c:if 标签,每个标签都围绕着一个不同的蒲公英数据表,该数据表应该是可见的还是不可见的,具体取决于用户单击哪个按钮。
如何设置它以在 Eclipse 中的 spring mvc hibernate maven 应用程序中工作?目前, .endsWith("cats") or dogs or all 子句在 Eclipse 中触发了一条错误消息,指出 endsWith() 不是 String 支持的方法。如何解决此问题以使其按预期工作?
这里是jsp的代码:
<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="datatables" uri="http://github.com/dandelion/datatables" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>PetClinic :: a Spring Framework demonstration</title>
<spring:url value="/webjars/bootstrap/2.3.0/css/bootstrap.min.css" var="bootstrapCss"/>
<link href="${bootstrapCss}" rel="stylesheet"/>
<spring:url value="/resources/css/petclinic.css" var="petclinicCss"/>
<link href="${petclinicCss}" rel="stylesheet"/>
<spring:url value="/webjars/jquery/2.0.3/jquery.js" var="jQuery"/>
<script src="${jQuery}"></script>
<!-- jquery-ui.js file is really big so we only load what we need instead of loading everything -->
<spring:url value="/webjars/jquery-ui/1.10.3/ui/jquery.ui.core.js" var="jQueryUiCore"/>
<script src="${jQueryUiCore}"></script>
<spring:url value="/webjars/jquery-ui/1.10.3/ui/jquery.ui.datepicker.js" var="jQueryUiDatePicker"/>
<script src="${jQueryUiDatePicker}"></script>
<!-- jquery-ui.css file is not that big so we can afford to load it -->
<spring:url value="/webjars/jquery-ui/1.10.3/themes/base/jquery-ui.css" var="jQueryUiCss"/>
<link href="${jQueryUiCss}" rel="stylesheet"></link>
</head>
<body>
<div class="container">
<table>
<tr>
<td width=160 valign="top">
<datatables:table id="owners" data="${selections}" cdn="true" row="owner" theme="bootstrap2"
cssClass="table table-striped" paginate="false" info="false"
cssStyle="width: 150px;" align="left" >
<datatables:column title="Name" cssStyle="width: 150px;" display="html">
<spring:url value="/owners?ownerID={ownerId}" var="ownerUrl">
<spring:param name="ownerId" value="${owner.id}"/>
</spring:url>
<a href="${fn:escapeXml(ownerUrl)}"><c:out value="${owner.firstName} ${owner.lastName}"/></a>
</datatables:column>
</datatables:table>
</td>
<td valign="top">
<h3>Owner:</h3>
<table class="table table-striped" style="width:600px;">
<tr>
<td><b><c:out value="${sel_owner.firstName} ${sel_owner.lastName}"/></b></td>
<td></td>
</tr>
<tr>
<td><c:out value="${sel_owner.address}"/></td>
<td><c:out value="${sel_owner.city}"/></td>
</tr>
<tr>
<td><c:out value="${sel_owner.telephone}"/></td>
<td></td>
</tr>
<tr>
<td colspan=2>
<spring:url value="/owners?ownerID={ownerId}&type=cats" var="owner_catsUrl">
<spring:param name="ownerId" value="${sel_owner.id}"/>
</spring:url>
<a href="${fn:escapeXml(owner_catsUrl)}" class="btn btn-info" >Show Cats</a>
<spring:url value="/owners?ownerID={ownerId}&type=dogs" var="owner_dogsUrl">
<spring:param name="ownerId" value="${sel_owner.id}"/>
</spring:url>
<a href="${fn:escapeXml(owner_dogsUrl)}" class="btn btn-info" >Show Dogs</a>
<spring:url value="/owners?ownerID={ownerId}&type=all" var="owner_allUrl">
<spring:param name="ownerId" value="${sel_owner.id}"/>
</spring:url>
<a href="${fn:escapeXml(owner_allUrl)}" class="btn btn-info" >Show All Pets</a>
</td>
</tr>
<c:if test="${pageContext.request.requestURI.endsWith('all')}">
<tr>
<td colspan=2>
<p>Pets</p>
<datatables:table id="pets" data="${sel_owner.pets}" cdn="true" row="pet" theme="bootstrap2"
cssClass="table table-striped" paginate="false" info="false" filter="false"
cssStyle="width: 350px;" align="left" >
<datatables:column title="Name" cssStyle="width: 200px;" display="html">
<c:out value="${pet.name}"/>
</datatables:column>
<datatables:column title="BirthDate" cssStyle="width: 300px;" display="html">
<joda:format value="${pet.birthDate}" pattern="yyyy-MM-dd"/>
</datatables:column>
<datatables:column title="Type" cssStyle="width: 200px;" display="html">
<c:out value="${pet.type.name}"/>
</datatables:column>
</datatables:table>
</td>
</tr>
</c:if>
<c:if test="${pageContext.request.requestURI.endsWith('cats')}">
<tr>
<td colspan=2>
<p>Cats</p>
<datatables:table id="cats" data="${sel_owner.cats}" cdn="true" row="cat" theme="bootstrap2"
cssClass="table table-striped" paginate="false" info="false" filter="false"
cssStyle="width: 350px;" align="left" >
<datatables:column title="Name" cssStyle="width: 200px;" display="html">
<c:out value="${cat.name}"/>
</datatables:column>
<datatables:column title="BirthDate" cssStyle="width: 300px;" display="html">
<joda:format value="${cat.birthDate}" pattern="yyyy-MM-dd"/>
</datatables:column>
<datatables:column title="Type" cssStyle="width: 200px;" display="html">
<c:out value="${cat.type.name}"/>
</datatables:column>
</datatables:table>
</td>
</tr>
</c:if>
<c:if test="${pageContext.request.requestURI.endsWith('dogs')}">
<tr>
<td colspan=2>
<p>Dogs</p>
<datatables:table id="dogs" data="${sel_owner.dogs}" cdn="true" row="dog" theme="bootstrap2"
cssClass="table table-striped" paginate="false" info="false" filter="false"
cssStyle="width: 350px;" align="left" >
<datatables:column title="Name" cssStyle="width: 200px;" display="html">
<c:out value="${dog.name}"/>
</datatables:column>
<datatables:column title="BirthDate" cssStyle="width: 300px;" display="html">
<joda:format value="${dog.birthDate}" pattern="yyyy-MM-dd"/>
</datatables:column>
<datatables:column title="Type" cssStyle="width: 200px;" display="html">
<c:out value="${dog.type.name}"/>
</datatables:column>
</datatables:table>
</td>
</tr>
</c:if>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
【问题讨论】:
标签: java eclipse spring jsp jstl