in jsp
<table width="100%" id='table1' border="0" cellspacing="2" cellpadding="2">
<tr class="tab-highlighted-2">
<td class="tab-highlighted-2" width="10%">
<div align="left">Project ID</div>
</td>
<td class="tab-highlighted-2" width="10%">
<div align="left">Project Name</div>
</td>
<td class="tab-highlighted-2" width="20%">
<div align="left">Cost Center</div>
</td>
<td class="tab-highlighted-2" width="20%">
<div align="left">Manager</div>
</td>
</tr>
<tr class="bg-row1">
<c:forEach items="${resultList}" var="resultList">
<td class="td-highlighted-2">
<div align="left">${resultList.Projid}</div>
</td>
<td class="td-highlighted-2">
<div align="left">${resultList.Projname}</div>
</td>
<td class="td-highlighted-2">
<div align="left">${resultList.Cost}</div>
</td>
<td class="td-highlighted-2">
<div align="left">${resultList.Manager}</div>
</td>
</tr>
</table>
in dao
public final class SearchProjDAO
{
private static InitialContext context;
String CLASS_NAME="DBConnectionFactory";
public ArrayList submitProjectDetails(SearchProjVO searchprojVO)
{
ArrayList ar = new ArrayList();
String methodname="createConnection";
Connection conn = null;
PreparedStatement psmt;
try {
System.out.println("in DAO");
System.out.println("searchprojVO id=="+searchprojVO.getProjid());
conn = DBConnection.getJNDIConnection();
ResultSet rs = null;
String query="select * from CR_EMPLOYEE_DETAILS";if(searchprojVO.getProjid()!=null || searchprojVO.getProjname()!=null || searchprojVO.getManager()!=null)
query=query+" where ";
if(searchprojVO.getProjid()!=null)
query=query+" PROJ_ID="+searchprojVO.getProjid();
if(searchprojVO.getProjname()!=null)
query=query+"PROJ_NAME="+searchprojVO.getProjname();
if(searchprojVO.getCost()!=null);
query=query+"PROJ_COST="+searchprojVO.getCost();
if(searchprojVO.getManager()!=null)
query=query+"PROJ_MANAGER="+searchprojVO.getManager();
psmt= conn.prepareStatement(query);
rs=psmt.executeQuery();
while(rs.next())
{
SearchProjVO projVO = new SearchProjVO();
projVO.setProjid(rs.getString("PROJ_ID"));
projVO.setManager(rs.getString("PROJ_NAME"));
projVO.setProjname(rs.getString("PROJ_COST"));
projVO.setManager(rs.getString("PROJ_MANAGER"));
ar.add(projVO);
}
System.out.println("conn==="+conn);
} catch (Exception e) {
e.printStackTrace(System.err);
}
return ar;
}
}
I spot several mistakes:
Here,
<c:forEach items="${resultList}" var="resultList">
You're overriding the list value with the value of the list item everytime. Don't do that. Give the var an unique variable name. The entity name is the most straightforward choice.
<c:forEach items="${resultList}" var="project">
Note that I'd personally also rename the nothing-saying resultList to a more self-explaining projects.
And here,
<tr class="bg-row1">
<c:forEach items="${resultList}" var="project">
the flow is wrong. You should print a new row inside each loop. Swap them.
<c:forEach items="${resultList}" var="project">
<tr class="bg-row1">
And here,
${resultList.Projid}
${resultList.Projname}
${resultList.Cost}
${resultList.Manager}
the property names must start with lowercase (and fix the item name to be the same as in var).
${project.projid}
${project.projname}
${project.cost}
${project.manager}
Note that I'd personally also get rid of proj prefix in some property names.
And finally you're forgotten a closing </c:forEach>.
</tr>
</c:forEach>
Unrelated to the concrete problem, your JDBC code is sensitive to SQL injection attacks and is leaking resources. Fix it as well.
Related
I have a form with some inputs; each input returns a list of data which is displayed in a table in another html page. Each input have a table to display it's data. My task is to do not display the data if the input is not entered by the user.
Here is my code
<!-- Country Table-->
<%for(int i = 0; i < countryList.length;i++){
if(countryList.length == 0)
break;
%>
<div class="box" align="center">
<table name="tab" align="center" class="gridtable">
<thead >
<tr>
<th style="width: 50%" scope="col">Entity Watch List Key</th>
<th style="width: 50%" scope="col">Watch List Name</th>
</tr>
</thead>
<tbody>
<tr>
<td style="width: 50%"><%out.println((String) (countryList[i].getEntityWatchListKey()));%></td>
<td style="width: 50%"><%out.println((String) (countryList[i].getEntityName()));%></td>
</tr>
</tbody>
</table>
</div>
<%}%>
I am using break to go out of the loop to do not display the table, is that true ?
You can use this condition before the for loop,
if(countryList.length != 0)
or
if(countryList.length > 0)
and then you need not use the break condition,
Furthermore the for loop you have currently defined will not work because if the length of the array is 0 then this condition i < countryList.length will become 0<0 and it will fail,so your for loop won't even be entered.So your current if condition if(countryList.length == 0) will not be accessed.
Please modify your code
<div class="box" align="center">
<table name="tab" align="center" class="gridtable">
<thead >
<tr>
<th style="width: 50%" scope="col">Entity Watch List Key</th>
<th style="width: 50%" scope="col">Watch List Name</th>
</tr>
</thead>
<tbody>
<%for(int i = 0; i < countryList.length;i++){
if(countryList.length > 0) %>
<tr>
<td style="width: 50%"><%out.println((String) (countryList[i].getEntityWatchListKey()));%></td>
<td style="width: 50%"><%out.println((String) (countryList[i].getEntityName()));%></td>
</tr>
<%}%>
</tbody>
</table>
</div>
For a good practice you have to repeat the row not the table.
I am building a Spring MVC web app, I have an object called NodeRel which is defined as below:
public class NodeRel {
private String fromNodeId;
private String toNodeId;
private String fromNodeName;
private String toNodeName;
private List<QuotaValueOnTime> fromNodeSend;
private List<QuotaValueOnTime> toNodeSend;
//getters and setters omitted
}
In the server side code, i obtained a list of NodeRels and bind it to the model. In the jsp page, I want to first loop through the List and then inside it, I want to loop though List. My jsp code:
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th class="center">Count</th>
<th>relation</th>
<th colspan='25'>Detail</th>
</tr>
</thead>
<tbody>
<c:forEach var="nodeRel" items="${nodeRelInfo}" varStatus="stc">
<tr>
<td rowspan="3">${stc.count}</td>
<td rowspan="3">${nodeRel.fromNodeName} --> ${nodeRel.toNodeName}</td>
<td>\</td>
<c:forEach var="x" begin="0" end="23" step="1">
<td>${x}</td>
</c:forEach>
</tr>
<tr>
<td>Send_A</td>
<c:forEach var="node" items="${nodeRelInfo.fromNodeSend}">
<td>${node.sumval}</td>
</c:forEach>
</tr>
<tr>
<td>Send_B</td>
<c:forEach var="x" begin="0" end="23" step="1">
<td>${x}</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
</div>
My code doesn't work and I got java.lang.NumberFormatException: For input string: "fromNodeSend" near the second loop:
<c:forEach var="node" items="${nodeRelInfo.fromNodeSend}">
<td>${node.sumval}</td>
</c:forEach>
What is wrong with my code?
Note that the variable ${nodeRelInfo} represents the List and the variable ${nodeRel} represents the each item you work with.
Thus the item you want to loop in the second loop is ${nodeRelInfo.fromNodeSend}. Change the second name of variable looped:
<c:forEach var="node" items="${nodeRel.fromNodeSend}">
<td>${node.sumval}</td>
</c:forEach>
It works on the same logic like Java for-each loop.
for (List nodeRel: nodeRelInfo) {
// bla blaa
for (String node: nodeRel.fromNodeSend()) {
System.out.println(node);
}
}
change your second loop like this because your variable name in parent loop is nodeRel not nodeRelInfo
<c:forEach var="node" items="${nodeRel.fromNodeSend}">
<td>${node.sumval}</td>
</c:forEach>
I have a created a small Java web application. I have made use of DAO and a JSP file. My issue is that when I enter an isbn number in the input field, if the book is found in the database, it displays me "Book Found" and the corresponding details. But if I enter an isbn number in the input field, and if the book is not found in the db, it still displays me "Book Found" but with isbn number 0 and book title "null" which I don't want. In that case, it should display me only "Book not found".
Note that the problem lies mainly in the JSP page.
Here is my full code: http://pastebin.com/cTZy4w6V (using pastebin since the code is too long)
Here is the JSP code:
<jsp:useBean id = "bm" class="book.ManagerBook" scope = "session"/>
<h1> Welcome to ABC Library</h1>
<form>
<table>
<tr>
<td> Enter Details </td>
<td><input type="text" name="isbn"></td>
<td><input type="submit" name="find" value="find"></td>
</tr>
</table>
<input type="hidden" name="submitted" value="true">
</form>
<%
Boolean submitted = Boolean.parseBoolean(request.getParameter("submitted"));
if(submitted){
int isbn = Integer.parseInt(request.getParameter("isbn"));
Book b2 = bm.findBook(isbn);
%>
<table>
<tr>
<td colspan=2>
<h2>Book Found</h2>
</td>
</tr>
<tr>
<td><h3>ISBN</h3></td>
<td><h3>Title</h3></td>
</tr>
<tr>
<td><%= b2.getIsbn()%></td>
<td><%= b2.getTitle() %></td>
</tr>
</table>
<%}else if(!submitted){ %>
<h3> Book Not Found</h3>
<% } %>
If possible, don't use scriptlets in jsp. It's a bad practice.
Try something like this:
if(submitted){
int isbn = Integer.parseInt(request.getParameter("isbn"));
Book b2 = bm.findBook(isbn);
if (b2.getTitle() != null) {
%>
<table>
<tr>
<td colspan=2>
<h2>Book Found</h2>
</td>
</tr>
<tr>
<td><h3>ISBN</h3></td>
<td><h3>Title</h3></td>
</tr>
<tr>
<td><%= b2.getIsbn()%></td>
<td><%= b2.getTitle() %></td>
</tr>
</table>
<% } else { %>
<h3> Book Not Found</h3>
<% } %> }
I am attempting to scrape the following html:
<table>
<tr>
<td class="cellRight" style="cursor:pointer;">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="cellRight" style="border:0;color:#0066CC;"
title="View summary" width="70%">92%</td>
<td class="cellRight" style="border:0;" width="30%">
</td>
</tr>
</table>
</td>
</tr>
<tr class="listroweven">
<td class="cellLeft" nowrap><span class="categorytab" onclick=
"showAssignmentsByMPAndCourse('08/03/2015','58100:6');" title=
"Display Assignments for Art 5 with Ms. Martinho"><span style=
"text-decoration: underline">58100/6 - Art 5 with Ms.
Martinho</span></span></td>
<td class="cellLeft" nowrap>
Martinho, Suzette<br>
<b>Email:</b> <a href="mailto:smartinho#mtsd.us" style=
"text-decoration:none"><img alt="" border="0" src=
"/genesis/images/labelIcon.png" title=
"Send e-mail to teacher"></a>
</td>
<td class="cellRight" onclick=
"window.location.href = '/genesis/parents?tab1=studentdata&tab2=gradebook&tab3=coursesummary&studentid=100916&action=form&courseCode=58100&courseSection=6&mp=MP4';"
style="cursor:pointer;">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="cellCenter"><span style=
"font-style:italic;color:brown;font-size: 8pt;">No
Grades</span></td>
</tr>
</table>
</td>
</tr>
<tr class="listrowodd">
<td class="cellLeft" nowrap><span class="categorytab" onclick=
"showAssignmentsByMPAndCourse('08/03/2015','58200:10');" title=
"Display Assignments for Family and Consumer Sciences 5 with Sheerin">
<span style="text-decoration: underline">58200/10 - Family and
Consumer Sciences 5 with Sheerin</span></span></td>
<td class="cellLeft" nowrap>
Sheerin, Susan<br>
<b>Email:</b> <a href="mailto:ssheerin#mtsd.us" style=
"text-decoration:none"><img alt="" border="0" src=
"/genesis/images/labelIcon.png" title=
"Send e-mail to teacher"></a>
</td>
<td class="cellRight" style="cursor:pointer;">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="cellCenter"><span style=
"font-style:italic;color:brown;font-size: 8pt;">No
Grades</span></td>
</tr>
</table>
</td>
</tr>
</table>
I am trying to extract the values for the student's grades, and if no grades are present, the value "no grades" which will be present in the html if this is the case. However, when I do a select request such as the following:
doc.select("[class=cellRight]")
I get an output where all of the grade values are listed twice (because they are nested within two elements containing the [class=cellRight] distinguisher, and the normal amount of "no grades" listing. So my question is, how can I only select the innermost child in a document which contains the distinguisher [class=cellRight]? (I have already dealt with the issue of a blank value) All help is appreciated!!
There are many possibilities to to this.
One would be this: Test for each "cellRight" element all its parents if they also carry that class. Discard if you find it:
List<Element> keepList = new ArrayList<>();
Elements els = doc.select(".cellRight");
for (Element el : els){
boolean keep = true;
for (Element parentEl : el.parents()){
if (parentEl.hasClass("cellRight")){
//parent has class as well -> discard!
keep = false;
break;
}
}
if (keep){
keepList.add(el);
}
}
//keepList now contains inner most elements with your class
Note that this is written without compiler and out of my head. There might be spelling/syntax errors.
Other note. your use of "[class=cellRight]" works well only if there is this single class. With multiple clsses in random order (which is totally to be expected) it is better to use the dot syntax ".cellRight"
I am using quartz to schedule jobs. Jobs are created in a "default" group and related information is passed as payload in form of a jobdetail map when using the schedule api.
Trigger trigger = new Trigger(...);
JobDetail jobDetail = new JobDetail(...);
jobDetail.put(...);
scheduler.schedule(trigger, jobDetail);
I want an API to be able to query the triggers in the database based on the payload sent in. For instance, I have "externalId" as part of the jobDetail.
I want to do something like
scheduler.getTriggers(new Criteria("externalId", externalId));
instead of fetching all the triggers in memory and then iterating over it. I searched a bit online but wasn't able to find an API to do the same.
EDIT: As of quartz, 2.1.5, there are a few new APIs
scheduler.getTrigger(triggerKey(jobId, jobGroupName)); // which can fetch the exact trigger given the triggerKey
scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME)); //this searches all the triggers for a group.
These are not available for quartz 1.8 though. One limitation still is that trigger searches need to be exact and cannot be LIKE % in nature
you can list all you tasks in quartz and collect the required
try this code (jsp):
SchedulerFactory sf = new StdSchedulerFactory(new File(getServletContext().getRealPath("/"), "WEB-INF/quartz.properties").getAbsolutePath());
Scheduler scheduler = sf.getScheduler();
try{
List<JobExecutionContext> jobList = scheduler.getCurrentlyExecutingJobs();
out.print("<h3>Current tasks: "+jobList.size()+"</h3>");
for(JobExecutionContext jec : jobList){
out.print("<hr>");
JobDetail jobDetail = jec.getJobDetail();
Trigger trigger = jec.getTrigger();
TriggerState state = scheduler.getTriggerState(trigger.getKey());
%>
<table style="width: 400px; background-color: #ffffff;">
<tr style="height: 23px;">
<td style="width: 190px;">
class:
</td>
<td style="width: 210px;">
<b><%=jec.getJobInstance().toString()%></b>
</td>
</tr>
<tr style="height: 23px;">
<td>
descr:
</td>
<td>
<i><%=jobDetail.getDescription()%></i>
</td>
</tr>
<tr style="height: 23px;">
<td>
next fire time:
</td>
<td>
<%=new Timestamp(trigger.getFireTimeAfter(new Timestamp(System.currentTimeMillis())).getTime())%>
</td>
</tr>
<tr style="height: 23px;">
<td>
prior:
</td>
<td>
<%=state.toString()%>
</td>
</tr>
</table>
<%
}
}catch(Exception ex){
out.print(ex.getMessage());
}
out.print("<hr>");
// getting all tasks
try{
List<String> jobGroups = scheduler.getJobGroupNames();
out.print("<h3>Triggers: "+jobGroups.size()+"</h3>");
for (String jName : jobGroups){
GroupMatcher<JobKey> matcher = GroupMatcher.groupEquals(jName);
Set keys = scheduler.getJobKeys(matcher);
Iterator iter = keys.iterator();
while (iter.hasNext()){
JobKey jk = (JobKey)iter.next();
JobDetail jobDetail = scheduler.getJobDetail(jk);
// JobDataMap jobDataMap = jobDetail.getJobDataMap();
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jk);
for(Trigger t : triggers){
out.print("<hr>");
TriggerState state = scheduler.getTriggerState(t.getKey());
%>
<table style="width: 400px; background-color: #ffffff;">
<tr style="height: 23px;">
<td style="width: 190px;">
group/class:
</td>
<td style="width: 210px;">
<b><%=t.getJobKey().toString()%></b>
</td>
</tr>
<tr style="height: 23px;">
<td style="width: 190px;">
descr:
</td>
<td style="width: 210px;">
<i><%=jobDetail.getDescription()%></i>
</td>
</tr>
<tr style="height: 23px;">
<td>
curr time:
</td>
<td>
<%=new Timestamp(System.currentTimeMillis())%>
</td>
</tr>
<tr style="height: 23px;">
<td>
next fire time:
</td>
<td>
<%=new Timestamp(t.getFireTimeAfter(new Timestamp(System.currentTimeMillis())).getTime())%>
</td>
</tr>
<tr style="height: 23px;">
<td>
prior:
</td>
<td>
<%=state.toString()%>
</td>
</tr>
</table>
<%
}
}
}
out.print("<hr>");
}catch (SchedulerException ex){
out.print(ex.getMessage());
}
Quartz stores JobDetails in a serialized map (JobDataMap) format. Unless deserialization it is hard to know what are the actual contents of the map.
In your case, I think there is no direct way, You may need to find a work around something like, storing job data map values into separate table which will have Trigger id associated with it, but I am not sure how salable this solution would be.