Getting equal symbol expected while using jstl - java

I am getting
org.apache.jasper.JasperException: /WEB-INF/AllClientBatchDetails.jsp(54,103) equal symbol expected
And here is the jsp
<%# page contentType="text/html;charset=UTF-8" language="java" import="java.util.*%>
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html:html xhtml="true">
<head>
<title><bean:message key="progressReporter.successpage.title"/></title>
<link rel="stylesheet" href="style.css">
<html:base/>
</head>
<body>
<c:choose>
<c:when test="${empty batchProgressMetricsList}">
<font color=<bean:message key="error.font.color" /> size=<bean:message key="error.font.size" />>
<bean:message key="error.no.active.batch" />
</font>
<br/>
</c:when>
<c:otherwise>
<h4><bean:message key="table.header" /></h4>
<table border=<bean:message key="table.border.size" />>
<tr>
<th><bean:message key="table.client.id.header" /></th>
<th><bean:message key="table.total.session.used" /></th>
<th><bean:message key="table.total.time.elapsed" /></th>
<th><bean:message key="table.imnts.completed" /></th>
<th><bean:message key="table.imnts.remaining" /></th>
<th><bean:message key="table.cores.allocated" /></th>
<th><bean:message key="table.time.remaining" /></th>
</tr>
<c:forEach var="aggregatedBatchProgressMetrics" items="${batchProgressMetricsList}">
<tr>
<td class="tdcenter">${aggregatedBatchProgressMetrics["clientId"]}</td>
<td class="tdcenter">${fn:substringBefore(aggregatedBatchProgressMetrics["sessionStats"]["sessionUsedTime"]/60000, '.')}mins${fn:substringBefore((aggregatedBatchProgressMetrics["sessionStats"]["sessionUsedTime"] % 60000)/1000, '.')}secs </td>
<td class="tdcenter">${fn:substringBefore(aggregatedBatchProgressMetrics["sessionStats"]["totalElapsedTime"]/60000, '.')}mins${fn:substringBefore((aggregatedBatchProgressMetrics["sessionStats"]["totalElapsedTime"] % 60000)/1000, '.')}secs</td>
<td class="tdcenter">${aggregatedBatchProgressMetrics["instrumentStats"]["totalImntsCompleted"]}</td>
<td class="tdcenter">${aggregatedBatchProgressMetrics["instrumentStats"]["totalImntsRemaining"]}</td>
<td class="tdcenter">${aggregatedBatchProgressMetrics["numberOfCores"]}</td>
<td class="tdcenter">${fn:substringBefore(aggregatedBatchProgressMetrics["sessionStats"]["sessionRemainingTime"]/60000, '.')}mins${fn:substringBefore((aggregatedBatchProgressMetrics["sessionStats"]["sessionRemainingTime"] % 60000)/1000, '.')}secs</td>
<br/>
<table>
<tr>
<th>session Id</th>
<th>taskId</th>
<th>task start time</th>
<th>task end time</th>
</tr>
${aggregatedBatchProgressMetrics["batchMetricsList"][0]}
${aggregatedBatchProgressMetrics["batchMetricsList"][1]}
${aggregatedBatchProgressMetrics["batchMetricsList"][2]}
<c:forEach var="batchProgressMetrics" items="${aggregatedBatchProgressMetrics["batchMetricsList"]}">
<tr>
<td class="tdcenter">${batchProgressMetrics["taskStats"]["sessionId"]}</td>
<td class="tdcenter">${batchProgressMetrics["taskStats"]["taskId"]}</td>
<td class="tdcenter">${batchProgressMetrics["taskStats"]["taskStartTime"]}</td>
<td class="tdcenter">${batchProgressMetrics["taskStats"]["taskEndTime"]}</td>
</tr>
</c:forEach>
</table>
<br/>
</tr>
</c:forEach>
</table>
</c:otherwise>
</c:choose>
<html:link page="/ProgressReporterForm.jsp">Go Back</html:link>
</body>
</html:html>
I have request attribute set to batchProgressMetricsList and its an array list of an object called. I have AggregatedBatchProgressMetrics. Inside aggregatedBatchProgressMetrics i have a method called getBatchMetricsList which return an arraylist of object called BatchProgressMetrics. If i run it without the nested c:forEach tag, it would just run fine, but if i include the nested one it just fails. Can somebody please help me?
Thanks in advance.
Almas

Try changing this:
items="${aggregatedBatchProgressMetrics["batchMetricsList"]}"
to this:
items="${aggregatedBatchProgressMetrics['batchMetricsList']}"

Replace
<c:forEach var="batchProgressMetrics" items="${aggregatedBatchProgressMetrics["batchMetricsList"]}">
by
<c:forEach var="batchProgressMetrics" items="${aggregatedBatchProgressMetrics['batchMetricsList']}">
The doublequote was closing the items value too soon which resulted in invalid EL. You should have spotted this soon enough when using an editor with decent sytnax highlighting (like here on SO :) ).

Related

JasperException when using f: in jsp page

I'm trying t learn Spring MVC and my project is buid a jsp form input a product
I added all jar jstl lib, and here is my taglib
<%#taglib uri="http://www.springframework.org/tags/form" prefix="f"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="s"%>
Here is my form appears bug
`<f:form action ="insertProduct.htm" method="GET" commandName="newProduct">
<table border ="1" cellpadding="2" cellspacing="2">
<tr>
<td>Product ID</td>
<td><f:input path="productId"/></td>
</tr>
<tr>
<td>Product Name</td>
<td><f:input path="productName"/></td>
</tr>
<tr>
<td>Price</td>
<td><f:input path="price"/></td>
</tr>
<tr>
<td>Description</td>
<td><f:input path="description"/><td>
</tr>
<tr>
<td>Status</td>
<td>
<f:select path="status">
<f:option value="true" label="Active"/>
<f:option value="false" label="Inactive"/>
</f:select>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Insert"/>
<input type="reset" value="Reset"/>
<input type="button" value="Back" onclick="history.go(-1)"/>
</td>
</tr>
</table>
</f:form>`
But i cant fix my bug. Please help me :(

Some other way to display data from sql table on jsp

I have used jstl to display particular data from table named status(all columns are string type) on found.jsp. In my table I have entered 1 and 0 under status column where 1 is for IN and 0 is for OUT.
found.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# page import="java.io.*,java.util.*,java.sql.*"%>
<%# page import="javax.servlet.http.*,javax.servlet.*" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Found page</title>
<style>
header {
background-color:teal;
color:white;
text-align:center;
padding:5px;
}
section {
height:270px;
width:1050px;
float:right;
padding:87px;
}
footer {
background-color:black;
float:bottom;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
</head>
<body style="background-color:lightsteelblue;">
<header><h3>File Status!!</h3>
<br>
</header>
<font color="black">back</font>
<form action=" LogoutServlet" method="post">
<input type="submit" value="Logout" >
</form>
<form method="POST">
File Number:<input type="text" name="status" value="" size="20" />
<input type="submit" value="submit" name="submit" />
</form>
<br>
<section>
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/login"
user="root" password="root"/>
<sql:query dataSource="${snapshot}" var="result">
SELECT * from status where fname="${param.status}";
</sql:query>
<table border="1" width="100%">
<tr>
<th>File Number</th>
Below is the column where 1 and 0 are shown under
<th>File Status(IN=1 and OUT=0)</th>
<th>File Department</th>
<th>Date and Time</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.fname}"/></td>
value comes from here
<td><c:out value="${row.fstatus}"/></td>
<td><c:out value="${row.department}"/></td>
<td><c:out value="${row.datetime}"/></td>
</tr>
</c:forEach>
</table>
</section>
<footer>
Copyright 2016 NSIC. All right reserved.
</footer>
</body>
</html>
I don't want 1 and 0 to be shown instead i want IN and OUT to be shown under the column and I don't want to change the database table entery from 1 and 0 to IN and OUT Is there a way I can do this?
you can do it with <c:choose> tag
<c:choose>
<c:when test="${row.fstatus=='1'}">
IN
</c:when>
<c:otherwise>
OUT
</c:otherwise>
</c:choose>

<c:url> tag and contextPath doesn't display properly path

I want to redirect a client to following paths when a particural text is clicked, but only Query and Remove works properly. My contextPath is "basics" and the jsp is displayed with path "http://localhost:8080/basics/". When i click on Update or Add user, then it redirects me to "http://localhost:8080/basics/basics/users" (the jsp file is users.jsp) but it should redirects respectively to "http://localhost:8080/basics/user/update/${customer.id}" and "http://localhost:8080/basics/user/add" What's wrong with that code?
users.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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Users</title>
//...style
</head>
<body>
<c:set value="${pageContext.request.contextPath}"
var="contextUrl" />
<c:set value="${contextUrl}/user/add" var="addUserUrl" />
<table style="width: 100%">
<tr>
<th>#ID</th>
<th>Name</th>
<th>Age</th>
<th>Country</th>
<td colspan="3"
style="background-color: #0CF323; text-align: center; border-top-color: #0CF323; border-right-color: #0CF323">
Add user
</td>
</tr>
<c:forEach var="customer" items="${customers}">
<c:set value="${contextUrl}/user/update/${customer.id}"
var="updateUserUrl" />
<c:set value="${contextUrl}/user/remove/${customer.id}"
var="removeUserUrl" />
<c:set value="${contextUrl}/user/${customer.id}" var="userUrl" />
<tr>
<td><c:out value="${customer.id }" /></td>
<td><c:out value="${customer.name }" /></td>
<td><c:out value="${customer.age }" /></td>
<td><c:out value="${customer.country.country }" /></td>
<td style="background-color: #17D0F5"> Query </td>
<td style="background-color: #FF8000"> Update </td>
<td style="background-color: #EC2727"> Remove </td>
</tr>
</c:forEach>
</table>
</body>
</html>
Try to replace this:
Add user
With using double quote "" and adding var="userVar":
Add user
And use the ${userVar} where you want.

jsp:param don't display the expected value

In my spring project, I have two layers for my views:
1) each method from my controller map directly a jsp page like that:
<jsp:include page="../../common/listagem.jsp">
<jsp:param name="name" value="Usuario"/>
<jsp:param name="elements" value="{['login','senha','pnome','unome','email']}"/>
</jsp:include>
2) my jsp page common/listagem.jsp is this:
<%# include file="../include/header.jsp" %>
<sec:authorize access="hasPermission(#user, 'cadastra_${param.name}')">
<p>
<button type="button" class="btn btn-sm btn-link link" data-action="/${param.name}/cadastra">
Cadastrar novo ${param.name}
</button>
</p>
</sec:authorize>
<table class="bordered">
<thead>
<tr>
<c:forEach var="item" items="${param.elements}">
<th> <c:out value="${item}"/> </th>
</c:forEach>
</tr>
</thead>
<tbody class="content">
</tbody>
<tfoot>
<tr>
<sec:authorize access="hasPermission(#user, 'altera_${param.name}')">
<td class="comando" data-nome="Altera" data-action="/${param.name}/altera"></td>
</sec:authorize>
<sec:authorize access="hasPermission(#user, 'remove_${param.name}')">
<td class="comando" data-nome="Remove" data-action="/${param.name}/remove"></td>
</sec:authorize>
</tr>
</tfoot>
</table>
<c:url value="/${param.name}/listagem.json" var="listagem"/>
<script>
$(document).ready(function(){
load_content("${listagem}", $('table.bordered'));
});
</script>
<%# include file="../include/footer.jsp" %>
My problem it's exactly with the page above. the final result for this code is that:
but instead should display only the title of the columns in the top and the code:
<c:url value="/${param.name}/listagem.json" var="listagem"/>
<script>
$(document).ready(function(){
load_content("${listagem}", $('table.bordered'));
});
</script>
should fill the table with data from the server (this code works in other project mine, where I don't use include files and jsp:param).
Anyone can see what's wrong with this code?
You can try with JSP JSTL Functions but it more like a JSON string so try with Jackson JSON Parser.
Find tutorial on Jackson parser here.
Sample code:
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="elements" value="${param.elements}" />
<c:forEach var="item"
items="${fn:split(fn:substring(elements,2,fn:length(elements)-2),',')}">
<c:out value="${item}" />
</c:forEach>
output:
'login' 'senha' 'pnome' 'unome' 'email'
OK, I solve this issue using an array for store the values, like that:
<jsp:param name="elements" value="login"/>
<jsp:param name="elements" value="pnome"/>
<jsp:param name="elements" value="unome"/>
<jsp:param name="elements" value="email"/>
and in the common jsp page:
<c:forEach var="item" items="${paramValues.elements}" varStatus="status">
<th class="col" data-property="<c:out value="${item}"/>">
<c:out value="${paramValues.label[status.index]}"/>
</th>
</c:forEach>

Enabling back button with Ajax

Following is my index.jsp:
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<s:head/>
<sj:head/>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript" src="validate.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<title>My Air - Home</title>
</head>
<body>
<div id="MainPage">
<jsp:include page="header.jsp"></jsp:include>
<div id="mainContent">
<jsp:include page="menubar.jsp"></jsp:include>
<div id="mainContentTop">
<div id="ContentLeft">
<jsp:include page="search.jsp"></jsp:include>
</div>
<div id="contentRight">
<jsp:include page="topdeals.jsp"></jsp:include>
</div>
</div>
</div>
<jsp:include page="footer.jsp"></jsp:include>
</div>
</body>
</html>
Following is my search.jsp:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>\
<s:form action="searchFlight" theme="css_xhtml" cssClass="form1small" name="searchFlightForm">
<div class="searchHeadersmall">Search Flight</div>
<div id="searchForm1">
<s:actionerror/>
<s:select list="#application.cityList" headerValue="--------Select--------" headerKey="select" name="searchFlightDetails.from" label="Leaving From"></s:select>
<s:select list="#application.destlist" headerValue="---------Select-------" headerKey="select" name="searchFlightDetails.to" label="Going To"></s:select>
<sj:datepicker id="date0" label="Date" name="searchFlightDetails.dateoftravel" readonly="true" minDate="0"/>
<s:select list="#{'1':'1','2':'2','3':'3','4':'4','5':'5'}" headerValue="" headerKey="" name="searchFlightDetails.noofpassengers" label="No of tickets" style="width:50%; float:left"></s:select>
<div class="inputsmall nobottombordersmall">
<s:radio label="Type" name="searchFlightDetails.nonstop"
list="#{'Y':'NonStop','N':'Normal'}"/>
</div>
<div id="submitdivid1">
<sj:submit value="Show Flights" targets="mainContent"/>
</div>
</div>
</s:form>
When form is submitted the following searchFlightSuccess.jsp is loaded in mainContent <div>:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<s:if test="#session.username!=null">
<jsp:include page="menubaruser.jsp"></jsp:include>
</s:if>
<s:if test="#session.username==null">
<jsp:include page="menubar.jsp"></jsp:include>
</s:if>
<div id="searchHeaderHistory">Search Results</div>
<div class="CSSTableGenerator">
<table>
<colgroup>
<col span="1" style="width: 5%;">
<col span="1" style="width: 10%">
<col span="1" style="width: 15%">
<col span="1" style="width: 10%">
<col span="1" style="width: 15%">
<col span="1" style="width: 15%">
<col span="1" style="width: 15%">
<col span="1" style="width: 5%">
<col span="1" style="width: 10%">
</colgroup>
<thead>
<tr>
<td colspan="9">From:<s:property
value="searchFlightDetails.from" />
To:<s:property value="searchFlightDetails.to" /></td>
</tr>
</thead>
<tbody>
<tr>
<td>Flight ID</td>
<td>Provider</td>
<td>Departure Source</td>
<td>Via</td>
<td>Via Arrival</td>
<td>Via Departure</td>
<td>Destination Arrival</td>
<td>Fare</td>
<td></td>
</tr>
<s:iterator value="searchedFlightsList" var="flights">
<tr>
<td align="center"><s:property
value="#flights.flightDetails.fid" /></td>
<td align="center"><s:property
value="#flights.flightDetails.providerDetails.pname" /></td>
<td align="center"><s:property value="#flights.sourcedepdate" />,<s:property
value="#flights.sourcedeptime" /> hrs</td>
<td align="center"><s:property
value="#flights.flightDetails.routeDetails.via" /></td>
<td align="center"><s:property value="#flights.viaarrdate" />,<s:property
value="#flights.viaarrtime" />hrs</td>
<td align="center"><s:property value="#flights.viadepdate" />,<s:property
value="#flights.viadeptime" />hrs</td>
<td align="center"><s:property value="#flights.destarrdate" />,<s:property
value="#flights.destarrtime" />hrs</td>
<td width="5%" align="center"><s:property
value="#flights.flightDetails.fares2d" /></td>
<td width="5%" align="center">
<s:form
action="passengerDetailsLink" method="get" theme="simple"
id="passengerDetailsLink_%{#flights.sid}">
<s:hidden value="%{#flights.sid}" name="sid" />
<s:hidden value="%{#flights.flightDetails.fares2d}" name="fare" />
<s:hidden value="%{searchFlightDetails.from}" name="from" />
<s:hidden value="%{searchFlightDetails.to}" name="to" />
<s:hidden value="%{searchFlightDetails.noofpassengers}"
name="passengers" />
<s:hidden value="1" name="flag" />
<sj:submit value="Book" targets="mainContent"
cssClass="orangebuttonsmall" />
</s:form></td>
</tr>
</s:iterator>
</tbody>
</table>
</div>
The scenario is as follows:
I entered some values in search.jsp. I submitted the form, and accordingly some results got loaded into the mainContent <div>. Since form was submitted using Struts 2 jQuery plugin submit , the URL remains the same and hence browser back button doesn't work. If I want to go back, how can I do that.
I read about some hash technique but , I am not able to apply it to this.
In the header tag of Struts2 jQuery use ajaxhistory attribute. Setting this attribute to true enabled browser history for Ajax requests. For details see wiki of header tag.

Categories