在请求属性中,我有对象列表(例如用户对象),那么如何循环它在我的 jsp 页面上显示数据?我可以使用<c:foreach>,但是我怎么能说它是 User 对象并访问它的属性呢?
我正在使用 jstl 进行小型测试。它不应该如何工作
这是小代码:
<c:set var="id" value="#{mBlog.blog.id}"/>
${id} //printing 4
<c:if test="${id > 0}">
<h:commandButton value="Update" action="#{mBlog.update}"/> //is not rendered
</c:if>
<c:if test="${id == 0}">
<h:commandButton value="Save" action="#{mBlog.save}"/> //is not rendered
</c:if>
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题。在显示器中我只看到 4 个,没有别的。
我正在使用joda-time-jsptags-1.1.1使用以下 taglib格式化和解析JSP 页面上基于Joda-Time的日期和时间对象。
<%@taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
Run Code Online (Sandbox Code Playgroud)
我在 Oracle 数据库中有使用标准 UTC 格式存储的日期。
使用以下 JSTL 标记,
<c:set var="startDate" value="${row.discountStartDate}"/>
<c:set var="endDate" value="${row.discountEndDate}"/>
Run Code Online (Sandbox Code Playgroud)
这两个日期分别以下列格式显示。
2013-02-16T22:31:59.000+05:30
2013-02-28T22:32:03.000+05:30
Run Code Online (Sandbox Code Playgroud)
我需要使用特定时区以特定格式显示这些日期。我正在尝试按如下方式解析这些日期。
<joda:parseDateTime var="startDate"
pattern="dd-MMM-yyyy HH:mm:ss"
value="${row.discountStartDate}"
dateTimeZone="Asia/Kolkata"/>
<joda:parseDateTime var="endDate"
pattern="dd-MMM-yyyy HH:mm:ss"
value="${row.discountStartDate}"
dateTimeZone="Asia/Kolkata"/>
Run Code Online (Sandbox Code Playgroud)
我希望以给定的格式和区域解析这些日期。但是,我收到以下异常。
java.lang.IllegalArgumentException:格式无效:“2013-02-16T22:31:59.000+05:30”在“13-02-16T22:31:59.000+05:30”处格式错误
如何解析这些日期
如何使用此标签调用类中的特定方法?
<jsp:useBean id="user" scope="??" class="com.example.User" type="com.example.User" />
我有一个 JSP,我在其中通过 JSTL c:forEach 循环显示元素。这是一个嵌套循环,如下所示:
<c:forEach items="${auditBudgetData.auditBudgetTierOneList}" var="auditBudgetTierOne" varStatus="tierOneCount">
** Some Code **
<c:forEach items="${auditBudgetTierOne.auditBudgetTierTwoList}" var="auditBudgetTierTwo" varStatus="tierTwoCount">
** Some Code **
<c:forEach items="${auditBudgetTierTwo.auditBudgetItemList}" var="auditBudgetItem" varStatus="budgetItemCount">
<input type="hidden" name="tierOneIndex" value="${tierOneCount.count}">
<input type="hidden" name="tierTwoIndex" value="${tierTwoCount.count}">
<input type="hidden" name="budgetItemIndex" value="${budgetItemCount.count}">
**Element rows displayed here**
Run Code Online (Sandbox Code Playgroud)
现在,当用户选择最内层循环中的任何元素行时,我必须在 JS 中获取值。如您所见,我正在尝试获取每个嵌套循环的计数,如下所示:
<input type="hidden" name="tierOneIndex" value="${tierOneCount.count}">
<input type="hidden" name="tierTwoIndex" value="${tierTwoCount.count}">
<input type="hidden" name="budgetItemIndex" value="${budgetItemCount.count}">
Run Code Online (Sandbox Code Playgroud)
并尝试在 JS 中获取输入字段的值,如下所示:
var tierOneIndex = $('input[name="tierOneIndex"]').val();
var tierTwoIndex = $('input[name="tierTwoIndex"]').val();
var budgetItemIndex = $('input[name="budgetItemIndex"]').val();
Run Code Online (Sandbox Code Playgroud)
但无论我选择什么元素,我总是得到:
tierOneIndex = 0
tierTwoIndex = 0
budgetItemIndex = …Run Code Online (Sandbox Code Playgroud) 我对 JSTL 很陌生。
现在我已经创建了一个 HashMap 并在 jsp 页面中呈现它。
这就是我创建 HashMap 的方式
在应用层:
public HashMap<String, String> uploadSmelter(){
HashMap<String, String> progress = new HashMap<String, String>();
try {
CompanyEntity instanceNew = (CompanyEntity) sessionFactory.getCurrentSession()
.createCriteria(CompanyEntity.class)
.add(Restrictions.eq("name", smObj.getName()))
.add(Restrictions.eq("metal", MetalEnum.valueOf(metal))).uniqueResult();
if (instanceNew != null){
//logger.info();
progress.put("error", Integer.toString(1));
progress.put("errorMsg", "Company : " +smObj.getName() + " for Metal: " + metal + " exists." );
}
}
return progress
}
Run Code Online (Sandbox Code Playgroud)
在控制器级别:
HashMap<String, String> result = new HashMap<String, String>();
result.put("error", "0");
result.put("update", "0");
result.put("create", "0");
HashMap<String, String> progress …Run Code Online (Sandbox Code Playgroud) 我正在使用 JSTL 标签来显示视图
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Run Code Online (Sandbox Code Playgroud)
我的表情
<td><c:out value="${project.projectStartdate}"/></td>
Run Code Online (Sandbox Code Playgroud)
但它显示在YYYY-MM-DD但我想要格式DD-MM-YYYY
JSTL 新手,并一直试图在 JSTL 中小写一个变量。我试过这个
<c:set value="${fn:toLowerCase(confirmedStatus)}" />
Run Code Online (Sandbox Code Playgroud)
并添加了标签库
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
Run Code Online (Sandbox Code Playgroud)
其中confirmedStatus 是一个枚举变量。
这是错误
Caused by: javax.servlet.jsp.JspTagException
at org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(SetSupport.java:245)
at org.apache.jsp.WEB_002dINF.views.tiles.clientOrder_jsp._jspx_meth_c_set_0(clientOrder_jsp.java:599)
at org.apache.jsp.WEB_002dINF.views.tiles.clientOrder_jsp._jspx_meth_c_when_1(clientOrder_jsp.java:561)
at org.apache.jsp.WEB_002dINF.views.tiles.clientOrder_jsp._jspx_meth_c_choose_1(clientOrder_jsp.java:516)
at org.apache.jsp.WEB_002dINF.views.tiles.clientOrder_jsp._jspx_meth_c_when_0(clientOrder_jsp.java:486)
at org.apache.jsp.WEB_002dINF.views.tiles.clientOrder_jsp._jspx_meth_c_choose_0(clientOrder_jsp.java:452)
at org.apache.jsp.WEB_002dINF.views.tiles.clientOrder_jsp._jspx_meth_c_forEach_0(clientOrder_jsp.java:389)
at org.apache.jsp.WEB_002dINF.views.tiles.clientOrder_jsp._jspService(clientOrder_jsp.java:154)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:558)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:489)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:972)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:417)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:906)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.Dispatcher.include(Dispatcher.java:178)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:1015)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:700)
at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
Run Code Online (Sandbox Code Playgroud) 我有一个primefaces面板,我想在其中p:fileUploader为几个元素提供primefaces 。在运行期间,不清楚会有多少项目。这是我的代码:
<h:form>
<p:panel id="grid" header="">
<h:panelGrid columns="2" cellpadding="5">
<c:forEach items="${bean.testCurrent}"
var="car" varStatus="i">
<p:outputLabel value="#{car.name}: " for="image${i.index}" />
<p:column>
<p:fileUpload id="image${i.index}"
fileUploadListener="#{bean.uploadImage}"
mode="advanced" dragDropSupport="true" multiple="false"
update="messages" sizeLimit="1000000"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
oncomplete="disableChoosing()"/>
<p:growl id="growl" showDetail="true" />
</p:column>
</c:forEach>
</h:panelGrid>
<p:commandButtonaction="#{bean.save()}" value="Save" />
<p:commandButton action="#{bean.cancel()}" value="Cancel" />
</p:panel>
</h:form>
Run Code Online (Sandbox Code Playgroud)
所以我的第一步是用 JSTL 的c:forEach. 这不起作用,因为 JSTL 在视图的构建期间运行,而 JSF 在视图组件树的渲染期间运行。
是否有可能在面板中实现 for 循环,或者是否有其他可能动态显示表单元素?
我正在尝试使用 JSTL 执行 JSP,但我无法执行。我有 Apache Tomcat 10,即jakarta.servlet.*不是javax.servlet.*. 因此,每当我使用 JSTL 1.2.5 文件执行 Web 应用程序时,就会收到错误消息:
jakarta.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/TagLibraryValidator
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:778)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Run Code Online (Sandbox Code Playgroud)
我试图在网上找到已解决的类似问题/问题,但找不到。如何在带有 Tomcat 10 的 JSP 中使用 JSTL?
我的索引 JSP 文件代码:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Tag Example</title>
</head>
<body>
<c:out value="${'Hello Yo'}"/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) jstl ×10
jsp ×7
java ×5
el ×2
jsf ×2
for-loop ×1
forms ×1
hibernate ×1
jakarta-ee ×1
javascript ×1
jodatime ×1
primefaces ×1
spring ×1
spring-mvc ×1
tomcat ×1