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>
Related
In a JSP page I use one form to get the entire DB and another form (and the related servlet request and the specific sort command). Once I sort a field, the form with the whole DB become empty, so the two Forms are not working one after another, as I expected.
For the moment I am not sure whether it's a HTML problem or something else, so I put just a second button to get a refresh. However, I assume there must be a smarter & simpler way using jQuery.
Thank you in advance!
<table cellpadding="10">
<form name="Refresh" action="AllPost">
<input type="submit" value="Refresh " /> ¦
</form>
<form name="F" action="SortedPost" id="formular" method="post">
<input type="submit" value="Sort: " />
<select name="Titl">
<c:forEach items="${AllPost}" var="p">
<option> ${p.Item} </option>
</c:forEach>
</select>
</form>
</table>
<table>
<c:forEach items="${SortedPost}" var="p">
<tr>
<td>ID: ${p.id}</td>
<td>bla bla : ${p.blabla}</td>
</tr>
</c:forEach>
</table>
<table>
<c:forEach items="${AllPost}" var="p">
<tr>
<td>${p.id}</td>
<td>bla bla : ${p.blabla}</td>
</tr>
</c:forEach>
</table>
I have a source code father JSP like that:
<table id="1" >
<tr>
<td>Table1</td>
</tr>
</table>
<div id=".insertCodeJSPInHere"></div>
<table id="2">
<tr>
<td>Table2</td>
</tr>
</table>
I want when i extend father JSP in children JSP then children JSP like that
<table id="1" >
<tr>
<td>Table1</td>
</tr>
</table>
<div id=".insertCodeJSPInHere"><h1>YenDV</h1></div>
<table id="2">
<tr>
<td>Table2</td>
</tr>
</table>
I write in children JSP:
<div id=".insertCodeJSPInHere"><h1>YenDV</h1></div>
<%#include file="fatherJSP.jsp" %>
But it's not work. I don't understand? HELP!
Try
<jsp:include page="fatherJSP.jsp">
The include directive:
<%#include file="something.html" %>
Used for static imports like html pages
Am trying to link from a JSP to a servlet . On clicking the button with the name="conf" I need to redirect to a servlet "/Initial" . The problem is when I use type="button" nothing happens, while when I use type="submit" the page gets directed to servlet "/Initial" and does the action there. Am not able to identify the problem.
Here is my code:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# page import="reg.serv.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2">Register Here</th>
</tr>
</thead>
<tbody>
<tr>
<td>Username</td>
<td><input type="text" class="" id="username" name="username1" value="" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password1" id="password" value="" /></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type="password" name="confirmpassword1" id="confirmpassword" value="" /></td>
</tr>
<tr>
<td>Mobile Number</td>
<td><input type="text" class="" id="mob" name="mob1" value="" /></td>
</tr>
<tr>
<td>Email ID</td>
<td><input type="text" class="" id="email" name="email1" value=" " /></td>
</tr>
<tr>
<td>Address</td>
<td><textarea id="address" name="address1"></textarea></td>
</tr>
<tr>
<td colspan="2">Already registered Login Here</td>
</tr>
</tbody>
<tr>
<td><input type="button" value="confirm" name="conf" /></td>
<td><input type="reset" value="Reset" /></td>
<td><input type="button" value="Cancel" name="Cr" onclick="openPage('Initial.jsp')" /></td>
</tr>
</table>
</form>
<script type="text/javascript">
function openPage(pageURL) {
window.location = pageURL;
}
</script>
<%
String x = request.getParameter("conf");
if (x != null && x.equals("confirm")) {
//response.sendRedirect("/Initial");
RequestDispatcher dispatcher = request.getRequestDispatcher("/Initial");
dispatcher.forward(request, response);
}
%>
</body>
</html>
Please help me . Any help would be greatly appreciated. Thanking You.
you have to write
<form action=/your_servlet_page_name>
And you have to use
<input type="submit" value="confirm" name="conf"/>
And also you have to map your servlet page into web.xml file like
<servlet-mapping>
<servlet-name>CheckLogin</servlet-name>
<url-pattern>/CheckLogin</url-pattern>
</servlet-mapping>
<form action = "servlet-name" method = "method in the servlet">
<input type ="submit" value = "val">
</form>
This is a simple way to do this. If you are using the latest jre i think 7 and up, you don't need to declare the servlet in your web.xml file. the #WebServlet("/servlet-url") will do the trick.
if you want to use type="button" instead of type="submit". you can use javascript function on the click on the button. Like
<script>
function doSubmit(){
var actionURL ="MENTION URL YOU WANT TO REDIRECT";
// perform your operations
myForm.submit(actionURL); OR
myForm.submit();
}
</script>
<form name="myForm">
<input type="button" name="conf" value="conf" obclick="doSubmit();">
</form>
hope it will help you.
try by changing the script only
<script type="text/javascript">
function openPage(pageURL)
{
window.location.href = pageURL;
}
</script>
function openPage(pageURL) {
window.location = pageURL;
}
In above code snippet, pageURL has to be an absolute URL which in case of dealing with servlets may vary.So instead of this below can be used
location.href = (location.href).substr(0, (location.href).lastIndexOf('xyz.jsp'))+"/abc";
Here 'abc' is the servlet to which we have to redirect the 'xyz.jsp' .This can even work if there are many buttons.The respective functions could be written to redirect to respective servlets.
Also it works in case of input type is "button" or "submit".
I dont get exactly what you are trying to do,but redirect is working with:
response.sendRedirect(request.getContextPath());
or
response.sendRedirect(String url);
This is a Spring MVC project.
So the following JSP
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<table>
<c:forEach items="${nameList}" var="studentList">
<tr>
<td><c:out value="${studentList.name}"/> ${studentList.regNo}</td>
</tr>
</c:forEach>
</table>
returns values like
Ramu
Somu
Mamu
Komu
I want to make each value as a post url, so that, if the user clicks any one link, I would like to submit as like the following jsp code does
<form method="post" action="number" id="number">
<div style="text-align: center;" >
<input width="20" type="text" data-validation="numbers" id="regNo" name="regNo" size="30" maxLength="50" placeholder="Enter Register Number">
</div>
</form>
I don't wanna do GET.
How can I do this? Please help me.
Use this
<td><a href='www.xyz.com:port/number?regNo=${studentList.regNo}><c:out value="${studentList.name}"/> </a></td>
And regNo you can get as the request parameter in controller
or
Path parameter in your controller like
<td><a href='www.xyz.com:port/number/${studentList.regNo}><c:out value="${studentList.name}"/> </a></td>
And modify your controller's configuration accordingly.
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 :) ).