I am developing a site in JSP, but I have some errors in my code.
Please help me with the following error:
org.apache.jasper.JasperException: An exception occurred processing JSP page/WEBINF/jsp/Invoice.jsp at line 165
162: <table>
163: <tr>
164: <td>Invoice No :</td>
165: <td><form:input path="invoiceno" /></td>
166: <td>Sr No:</td>
167: <td><form:input path="srno" /></td>
168: </tr>
root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'MetalBean' available as request attribute
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:165)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:152)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:143)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127)
org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:103)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
org.apache.jsp.WEB_002dINF.jsp.Invoice_jsp._jspx_meth_form_005finput_005f17(Invoice_jsp.java:1005)
org.apache.jsp.WEB_002dINF.jsp.Invoice_jsp._jspx_meth_form_005fform_005f1(Invoice_jsp.java:895)
org.apache.jsp.WEB_002dINF.jsp.Invoice_jsp._jspService(Invoice_jsp.java:116)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:12
I have created the bean class as MetalBean
my jsp file is...
<form:form method="post" action="/insertMetalTransaction" modelAttribute="MetalBean">
<table>
<tr>
<td>Invoice No :</td>
<td><form:input path="invoiceNo" /></td>
<td>Sr No:</td>
<td><form:input path="srno" /></td>
</tr>
<tr>
<td>Date :</td>
<td><form:input path="date" /></td>
<td>Transaction Type :</td>
<td><form:input path="transactionType" /></td>
</tr>
<tr>
<td>Weight :</td>
<td><form:input path="weight" /></td>
<td>Tunch :</td>
<td><form:input path="tunch" /></td>
</tr>
<tr>
<td>Fine :</td>
<td><form:input path="fine" /></td>
<td>Certificate No :</td>
<td><form:input path="certificateNo" /></td>
</tr>
<tr>
<td>Sale Type :</td>
<td><form:input path="saleType" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Insert" /></td>
</tr>
</table>
<!-- Here is the Table -->
<table border="1">
<tr>
<td class="heading">Invoice No.</td>
<td class="heading">Sr No.</td>
<td class="heading">Date</td>
<td class="heading">Transaction Type</td>
<td class="heading">Weight</td>
<td class="heading">Tunch</td>
<td class="heading">Fine</td>
<td class="heading">Certificate No</td>
<td class="heading">Sale Type</td>
<td class="heading">Edit</td>
<td class="heading">Delete</td>
</tr>
<c:forEach var="in" items="${map.metalList}">
<tr id="${in.invoiceNo}">
<td>${in.invoiceNo}</td>
<td>${in.srno}</td>
<td>${in.date}</td>
<td>${in.transactionType}</td>
<td>${in.weight}</td>
<td>${in.tunch}</td>
<td>${in.fine}</td>
<td>${in.certificateNo}</td>
<td>${in.saleType}</td>
<td><a id="edit-${in.invoiceNo}" onclick='edit(this)' href="#" >Edit</a></td>
<td>Delete</td>
</tr>
</c:forEach>
</table>
My Controller class...
//////////////For Main Page//////////////////////////////////////////////////////////
#RequestMapping("/getList")
public ModelAndView getUserLIst() {
List<usercreation> userList = ucDaoImpl.getUserList();
return new ModelAndView("userList", "userList", userList);
}
#RequestMapping("/Invoice")
public ModelAndView loginUser1(Model model) {
model.addAttribute("InvoiceBean", new InvoiceBean());
Map<String, Object> map = new HashMap<String, Object>();
List<InvoiceBean> invoiceList = iDaoImpl.getInvoiceBeans();
map.put("invoiceList",invoiceList);
System.out.println(invoiceList);
List<MetalBean> metalList = mDaoImpl.getMetalBeans();
map.put("metalList",metalList);
System.out.println(metalList);
return new ModelAndView("Invoice","map",map);
}
You're binding your form to the model attribute MetalBean, but this is not available when a request to /Invoice is made. Only an InvoiceBean is available at that point.
Modify your controller method and set the MetalBean in the model.
#RequestMapping("/Invoice")
public ModelAndView loginUser1(Model model) {
model.addAttribute("MetalBean", new MetalBean());
...
Related
I am unable to locate the date, month and year in bootstrap date picker. While I am trying to inspect the element in calendar, the calendar is getting closed and unable to locate the element.
It should not be a problem to open the page, click the control which is responsible for showing the calendar and invoke WebDriver.getPageSource() function.
Example code (it uses WebDriverWait to ensure that the calendar widget is there as it might be the case it's loaded after DOM is ready due to asynchronous nature of AJAX calls) :
driver.get("https://eonasdan.github.io/bootstrap-datetimepicker/");
new WebDriverWait(driver, 10)
.until(ExpectedConditions
.elementToBeClickable(By
.xpath("//span[contains(#class,'calendar')]")))
.click();
Files.write(Paths.get("response.html"), driver.getPageSource().getBytes(StandardCharsets.UTF_8));
Example output from the above page:
<div class="bootstrap-datetimepicker-widget dropdown-menu bottom"
style="display: block; top: 34px; bottom: auto; left: 0px; right: auto;">
<ul class="list-unstyled">
<li class="collapse in">
<div class="datepicker">
<div class="datepicker-days" style="display: block;">
<table class="table-condensed">
<thead>
<tr>
<th class="prev" data-action="previous"><span
class="glyphicon glyphicon-chevron-left"
title="Previous Month"></span></th>
<th class="picker-switch" data-action="pickerSwitch"
colspan="5" title="Select Month">July 2019
</th>
<th class="next" data-action="next"><span
class="glyphicon glyphicon-chevron-right"
title="Next Month"></span></th>
</tr>
<tr>
<th class="dow">Su</th>
<th class="dow">Mo</th>
<th class="dow">Tu</th>
<th class="dow">We</th>
<th class="dow">Th</th>
<th class="dow">Fr</th>
<th class="dow">Sa</th>
</tr>
</thead>
<tbody>
<tr>
<td data-action="selectDay" data-day="06/30/2019"
class="day old weekend">30
</td>
<td data-action="selectDay" data-day="07/01/2019"
class="day">1
</td>
<td data-action="selectDay" data-day="07/02/2019"
class="day">2
</td>
<td data-action="selectDay" data-day="07/03/2019"
class="day">3
</td>
<td data-action="selectDay" data-day="07/04/2019"
class="day">4
</td>
<td data-action="selectDay" data-day="07/05/2019"
class="day">5
</td>
<td data-action="selectDay" data-day="07/06/2019"
class="day weekend">6
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="07/07/2019"
class="day weekend">7
</td>
<td data-action="selectDay" data-day="07/08/2019"
class="day">8
</td>
<td data-action="selectDay" data-day="07/09/2019"
class="day">9
</td>
<td data-action="selectDay" data-day="07/10/2019"
class="day">10
</td>
<td data-action="selectDay" data-day="07/11/2019"
class="day">11
</td>
<td data-action="selectDay" data-day="07/12/2019"
class="day">12
</td>
<td data-action="selectDay" data-day="07/13/2019"
class="day weekend">13
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="07/14/2019"
class="day weekend">14
</td>
<td data-action="selectDay" data-day="07/15/2019"
class="day">15
</td>
<td data-action="selectDay" data-day="07/16/2019"
class="day">16
</td>
<td data-action="selectDay" data-day="07/17/2019"
class="day">17
</td>
<td data-action="selectDay" data-day="07/18/2019"
class="day">18
</td>
<td data-action="selectDay" data-day="07/19/2019"
class="day">19
</td>
<td data-action="selectDay" data-day="07/20/2019"
class="day weekend">20
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="07/21/2019"
class="day weekend">21
</td>
<td data-action="selectDay" data-day="07/22/2019"
class="day active today">22
</td>
<td data-action="selectDay" data-day="07/23/2019"
class="day">23
</td>
<td data-action="selectDay" data-day="07/24/2019"
class="day">24
</td>
<td data-action="selectDay" data-day="07/25/2019"
class="day">25
</td>
<td data-action="selectDay" data-day="07/26/2019"
class="day">26
</td>
<td data-action="selectDay" data-day="07/27/2019"
class="day weekend">27
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="07/28/2019"
class="day weekend">28
</td>
<td data-action="selectDay" data-day="07/29/2019"
class="day">29
</td>
<td data-action="selectDay" data-day="07/30/2019"
class="day">30
</td>
<td data-action="selectDay" data-day="07/31/2019"
class="day">31
</td>
<td data-action="selectDay" data-day="08/01/2019"
class="day new">1
</td>
<td data-action="selectDay" data-day="08/02/2019"
class="day new">2
</td>
<td data-action="selectDay" data-day="08/03/2019"
class="day new weekend">3
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="08/04/2019"
class="day new weekend">4
</td>
<td data-action="selectDay" data-day="08/05/2019"
class="day new">5
</td>
<td data-action="selectDay" data-day="08/06/2019"
class="day new">6
</td>
<td data-action="selectDay" data-day="08/07/2019"
class="day new">7
</td>
<td data-action="selectDay" data-day="08/08/2019"
class="day new">8
</td>
<td data-action="selectDay" data-day="08/09/2019"
class="day new">9
</td>
<td data-action="selectDay" data-day="08/10/2019"
class="day new weekend">10
</td>
</tr>
</tbody>
</table>
</div>
<div class="datepicker-months" style="display: none;">
<table class="table-condensed">
<thead>
<tr>
<th class="prev" data-action="previous"><span
class="glyphicon glyphicon-chevron-left"
title="Previous Year"></span></th>
<th class="picker-switch" data-action="pickerSwitch"
colspan="5" title="Select Year">2019
</th>
<th class="next" data-action="next"><span
class="glyphicon glyphicon-chevron-right"
title="Next Year"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7"><span data-action="selectMonth"
class="month">Jan</span><span
data-action="selectMonth"
class="month">Feb</span><span
data-action="selectMonth"
class="month">Mar</span><span
data-action="selectMonth"
class="month">Apr</span><span
data-action="selectMonth"
class="month">May</span><span
data-action="selectMonth"
class="month">Jun</span><span
data-action="selectMonth"
class="month active">Jul</span><span
data-action="selectMonth"
class="month">Aug</span><span
data-action="selectMonth"
class="month">Sep</span><span
data-action="selectMonth"
class="month">Oct</span><span
data-action="selectMonth"
class="month">Nov</span><span
data-action="selectMonth" class="month">Dec</span>
</td>
</tr>
</tbody>
</table>
</div>
<div class="datepicker-years" style="display: none;">
<table class="table-condensed">
<thead>
<tr>
<th class="prev" data-action="previous"><span
class="glyphicon glyphicon-chevron-left"
title="Next Decade"></span></th>
<th class="picker-switch" data-action="pickerSwitch"
colspan="5" title="Select Decade">2014-2025
</th>
<th class="next" data-action="next"><span
class="glyphicon glyphicon-chevron-right"
title="Previous Decade"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7"><span data-action="selectYear" class="year">2014</span><span
data-action="selectYear"
class="year">2015</span><span
data-action="selectYear"
class="year">2016</span><span
data-action="selectYear"
class="year">2017</span><span
data-action="selectYear"
class="year">2018</span><span
data-action="selectYear"
class="year active">2019</span><span
data-action="selectYear"
class="year">2020</span><span
data-action="selectYear"
class="year">2021</span><span
data-action="selectYear"
class="year">2022</span><span
data-action="selectYear"
class="year">2023</span><span
data-action="selectYear"
class="year">2024</span><span
data-action="selectYear" class="year">2025</span>
</td>
</tr>
</tbody>
</table>
</div>
<div class="datepicker-decades" style="display: none;">
<table class="table-condensed">
<thead>
<tr>
<th class="prev" data-action="previous"><span
class="glyphicon glyphicon-chevron-left"
title="Previous Century"></span></th>
<th class="picker-switch" data-action="pickerSwitch"
colspan="5">1999-2099
</th>
<th class="next" data-action="next"><span
class="glyphicon glyphicon-chevron-right"
title="Next Century"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7"><span data-action="selectDecade"
class="decade" data-selection="2005">2000 - 2011</span><span
data-action="selectDecade" class="decade"
data-selection="2017">2012 - 2023</span><span
data-action="selectDecade" class="decade"
data-selection="2029">2024 - 2035</span><span
data-action="selectDecade" class="decade"
data-selection="2041">2036 - 2047</span><span
data-action="selectDecade" class="decade"
data-selection="2053">2048 - 2059</span><span
data-action="selectDecade" class="decade"
data-selection="2065">2060 - 2071</span><span
data-action="selectDecade" class="decade"
data-selection="2077">2072 - 2083</span><span
data-action="selectDecade" class="decade"
data-selection="2089">2084 - 2095</span><span
data-action="selectDecade" class="decade"
data-selection="2101">2096 - 2107</span><span></span><span></span><span></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</li>
<li class="picker-switch accordion-toggle">
<table class="table-condensed">
<tbody>
<tr>
<td><a data-action="togglePicker" title="Select Time"><span
class="glyphicon glyphicon-time"></span></a></td>
</tr>
</tbody>
</table>
</li>
<li class="collapse">
<div class="timepicker">
<div class="timepicker-picker">
<table class="table-condensed">
<tbody>
<tr>
<td><a href="#" tabindex="-1" title="Increment Hour"
class="btn" data-action="incrementHours"><span
class="glyphicon glyphicon-chevron-up"></span></a>
</td>
<td class="separator"></td>
<td><a href="#" tabindex="-1" title="Increment Minute"
class="btn" data-action="incrementMinutes"><span
class="glyphicon glyphicon-chevron-up"></span></a>
</td>
<td class="separator"></td>
</tr>
<tr>
<td><span class="timepicker-hour"
data-time-component="hours" title="Pick Hour"
data-action="showHours">05</span></td>
<td class="separator">:</td>
<td><span class="timepicker-minute"
data-time-component="minutes" title="Pick Minute"
data-action="showMinutes">46</span></td>
<td>
<button class="btn btn-primary"
data-action="togglePeriod" tabindex="-1"
title="Toggle Period">PM
</button>
</td>
</tr>
<tr>
<td><a href="#" tabindex="-1" title="Decrement Hour"
class="btn" data-action="decrementHours"><span
class="glyphicon glyphicon-chevron-down"></span></a>
</td>
<td class="separator"></td>
<td><a href="#" tabindex="-1" title="Decrement Minute"
class="btn" data-action="decrementMinutes"><span
class="glyphicon glyphicon-chevron-down"></span></a>
</td>
<td class="separator"></td>
</tr>
</tbody>
</table>
</div>
<div class="timepicker-hours" style="display: none;">
<table class="table-condensed">
<tbody>
<tr>
<td data-action="selectHour" class="hour">12</td>
<td data-action="selectHour" class="hour">01</td>
<td data-action="selectHour" class="hour">02</td>
<td data-action="selectHour" class="hour">03</td>
</tr>
<tr>
<td data-action="selectHour" class="hour">04</td>
<td data-action="selectHour" class="hour">05</td>
<td data-action="selectHour" class="hour">06</td>
<td data-action="selectHour" class="hour">07</td>
</tr>
<tr>
<td data-action="selectHour" class="hour">08</td>
<td data-action="selectHour" class="hour">09</td>
<td data-action="selectHour" class="hour">10</td>
<td data-action="selectHour" class="hour">11</td>
</tr>
</tbody>
</table>
</div>
<div class="timepicker-minutes" style="display: none;">
<table class="table-condensed">
<tbody>
<tr>
<td data-action="selectMinute" class="minute">00</td>
<td data-action="selectMinute" class="minute">05</td>
<td data-action="selectMinute" class="minute">10</td>
<td data-action="selectMinute" class="minute">15</td>
</tr>
<tr>
<td data-action="selectMinute" class="minute">20</td>
<td data-action="selectMinute" class="minute">25</td>
<td data-action="selectMinute" class="minute">30</td>
<td data-action="selectMinute" class="minute">35</td>
</tr>
<tr>
<td data-action="selectMinute" class="minute">40</td>
<td data-action="selectMinute" class="minute">45</td>
<td data-action="selectMinute" class="minute">50</td>
<td data-action="selectMinute" class="minute">55</td>
</tr>
</tbody>
</table>
</div>
</div>
</li>
</ul>
</div>
db.html
<div th:each="pr, stat: *{mergeMap}">
<tr>
<td><input type="text" name="key" th:value="${pr.key}" /></td>
<td><input type="text" name="value" th:value="${pr.value}" /></td>
</tr>
</div>
On submitting this input, i always get mergeMap to be empty at the Spring Controller. What should be done to get the value of mergeMap?
Controller.java
#RequestMapping(value = "/shot")
public String saveMergeProducts(#ModelAttribute(value="prod") MergedProductInfoDTO prod, BindingResult bindingResult,
Model model, HttpServletRequest request) {
System.out.println(prod.toString());
return "forward:/backoffice/db";
}
HTML
<form action="#" th:action="#{shot}" method="POST" th:object="${prod}">
<tr>
<td><span th:text="${index.index}"></span></td>
<td><input type="text" name="id" th:value="*{id}" th:readonly="readonly" /></td>
<td><input type="text" name="categoryName" th:value="*{categoryName}" th:readonly="readonly" /></td>
<td><input type="text" name="subCategoryName" th:value="*{subCategoryName}" th:readonly="readonly" /></td>
<td><input type="text" name="productBrand" th:value="*{productBrand}" /></td>
<td><input type="text" name="productSubBrand" th:value="*{productSubBrand}" /></td>
<td><input type="text" name="series" th:value="*{series}" /></td>
<td><input type="text" name="model" th:value="*{model}" /></td>
</tr>
<tr>
<td colspan="7">
<tr>
<th>KEY</th>
<th>VALUE</th>
</tr>
<div th:each="pr, stat: *{mergeMap}">
<tr>
<td><input type="text" name="mergeMapKey" th:value="${pr.key}" /></td>
<td><input type="text" name="mergeMapValue" th:value="${pr.value}" /></td>
</tr>
</div>
</table>
</td>
<td><input type="text" name="tags" th:value="*{tags}" /></td>
<td><input type="submit" value="Submit" /></td>
</tr>
To access the Map property of the form-backing bean, use the __${...}__ preprocessor
<div th:each="pr, stat: *{mergeMap}">
<tr>
<td><input type="text" name="value" th:value="${pr.key}" readonly="true"/></td>
<td><input type="text" name="value" th:field="*{mergeMap[__${pr.key}__]}"/></td>
</tr>
</div>
What it does it evaluates the inner expression first before evaluating the whole expression. Note that in this case, ${pr.key} should not be modified so that the update will be reflected to the map property of the bean bound to the form.
Reference : http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#dynamic-fields
I am trying to insert values id(Not Auto Incr), Eid, Ename, Esalary, Eaddress from mysql table named employee but following exception is showed
java.sql.SQLException: Unknown column 'jay' in 'field list'
1. Insert.jsp
<form method="post" action="Insertbackend.jsp">
<table border="1">
<tr>
<td style="font-size:20px ">Enter Employee ID: </td>
<td><input type="text" name="id" /></td>
</tr>
<tr>
<td style="font-size:20px ">Enter Employee Name: </td>
<td><input type="text" name="En" /></td>
</tr>
<tr>
<td style="font-size:20px ">Enter Employee Salary: </td>
<td><input type="text" name="Es" /></td>
</tr>
<tr>
<td style="font-size:20px ">Enter Employee Address: </td>
<td><input type="text" name="Ea" /></td>
</tr>
<tr>
<td style="border-right:0em;"></td>
<td style="border-left:0em;"><input type="submit" value="Insert"></td>
</tr>
</table>
</form>
2. Insetbackend.jsp
<%
try
{
String eid=(String)request.getParameter("id");
String en=(String)request.getParameter("En");
String es=(String)request.getParameter("Es");
String ea=(String)request.getParameter("Ea");
Class.forName("com.mysql.jdbc.Driver");
Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement s=c.createStatement();
s.executeUpdate("insert into employee values("+eid+","+en+","+es+","+ea+")");
c.close();
s.close();
}
catch(Exception e)
{
out.println(e);
}
%>
Edit this line:
s.executeUpdate("insert into employee values("+eid+","+en+","+es+","+ea+")");
in to:
s.executeUpdate("insert into employee values('"+eid+"','"+en+"','"+es+"','"+ea+"')");
Since you are using all strings, you must add the quotes surrounded..
I try to execute this code it will show the following error:
java.sql.SQLException.Operation not allowed after ResultSet closed
This is my code.in this code itself shows the above error..
<table cellspacing="0">
<%
try{
ResultSet rs1=st.executeQuery("select u.post_id,u.userid,u.post_txt from requestdetails as r inner join user_post as u on r.frdname=u.userid where r.userid='"+id+"'");
while(rs1.next()){
int post_id=rs1.getInt(1);
int fid=rs1.getInt(2);
System.out.println("iiii "+fid);
String text=rs1.getString(3);
System.out.println("txttt "+text);
ResultSet rs3=stat.executeQuery("select * from userdetails where userid='"+fid+"'");
if(rs3.next()){
String na=rs3.getString("username");
System.out.println("username "+na);
String img=rs3.getString("profilepic");
System.out.println("imgee "+img);
%>
<tr>
<td width="5%" style="padding-left:25;" rowspan="2"> <img src="images/<%=img%>" height="60" width="55"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3" style="padding:7;"><%=rs3.getString("username") %> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td colspan="3" style="padding-left:7;"><%=text %></td>
</tr>
<%
ResultSet rr=st.executeQuery("select * from comment_status where post_id='"+post_id+"'");
while(rr.next()){
int uid=rr.getInt("userid");
String cmt=rr.getString("comment");
ResultSet rrr=stat.executeQuery("select * from userdetails where userid='"+uid+"'");
if(rrr.next()){
%>
<tr>
<td> </td>
<td width="4%" bgcolor="#EDEFF4" style="padding-left:12;" rowspan="2"> <img src="" height="40" width="47"> </td>
<td bgcolor="#EDEFF4" style="padding-left:7;" > <%=rrr.getString("username") %> </td>
<td align="right" rowspan="2" bgcolor="#EDEFF4">
</tr>
<tr>
<td> </td>
<td bgcolor="#EDEFF4" style="padding-left:7;" colspan="2"><%=cmt %></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<%
}
}
%>
<tr>
<td> </td>
<td width="4%" style="padding-left:17;" bgcolor="#EDEFF4" rowspan="2"> <img src="images/" height="33" width="33"> </td>
<td bgcolor="#EDEFF4" colspan="2" style="padding-top:15;">
<form method="post" name="commenting" onSubmit="return blank_comment_check()" action="commentstatus.jsp">
<input type="text" name="comment_txt" placeholder="Write a comment..." maxlength="420" style="width:100px;" id="">
<input type="hidden" name="postid" value="<%=post_id%>">
<input type="hidden" name="userid" value="">
<input type="submit" name="comment" style="display:none;">
</form>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="4"align="right" style="border-top:outset; border-top-width:thin;"> </td>
</tr>
<%
}
}
}catch(Exception e){
e.printStackTrace();
}
%>
</table>
</div>
I don't know what mistake I've done in above code.
After I change the code like this, it's working fine...
Statement stt=con.createStatement();
ResultSet rs1=stt.executeQuery("select u.post_id,u.userid,u.post_txt from requestdetails as r inner join user_post as u on r.frdname=u.userid where r.userid='"+id+"'");
while(rs1.next()){
int post_id=rs1.getInt(1);
int fid=rs1.getInt(2);
System.out.println("iiii "+fid);
String text=rs1.getString(3);
System.out.println("txttt "+text);
Statement st1=con.createStatement();
ResultSet rs3=st1.executeQuery("select * from userdetails where userid='"+fid+"'");
if(rs3.next()){
String na=rs3.getString("username");
System.out.println("username "+na);
String img=rs3.getString("profilepic");
System.out.println("imgee "+img);
I made the mistake of using the same statement for all queries.
When I created different statements object for the solution it works fine.
I am using jQuery datepicker for a textfield in my application.I am able to insert data properly in (dd-MM-yy) format.But the problem is getting date in diiferent format(date and time with timezone) back to the text field while validating which leads to an exception.
Student.java
public class Student {
private final static Logger logger=Logger.getLogger(Student.class);
private Integer sid;
private String firstName;
private String middleName;
private String lastName;
private String fatherName;
private String motherName;
private Date dateOfBirth;
private Integer admissionNo;
private Date dateOfJoining;
private String standard;
private String section;
private String medium;
private Address address;
StudentController.java
#Controller
#RequestMapping("/student")
public class StudentController {
private final static Logger logger=Logger.getLogger(StudentController.class);
#Autowired
private StudentService studentService;
#Autowired
private StudentValidator studentValidator;
#RequestMapping("/form")
public ModelAndView getForm(#ModelAttribute Student student,Model model){
initModelList(model);
logger.info("This is a message");
return new ModelAndView("form");
}
#RequestMapping("/register")
public String addStudent(#ModelAttribute("student") Student student, Model model, BindingResult bindingResult,SessionStatus status){
studentService.addStudent(student);
initModelList(model);
studentValidator.validate(student, bindingResult);
if(bindingResult.hasErrors()){
return "form";
}else{
logger.info("Student added successfully...");
status.setComplete();
return "redirect:list";
}
}
#InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yy");
dateFormat.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, false));
}
private void initModelList(Model model){
List<String> standardList=new ArrayList<String>();
standardList.add("--Select--");
standardList.add("I");
standardList.add("II");
standardList.add("III");
standardList.add("IV");
standardList.add("V");
standardList.add("VI");
standardList.add("VII");
standardList.add("VIII");
standardList.add("IX");
standardList.add("X");
model.addAttribute("standard",standardList);
List<String> mediumList=new ArrayList<String>();
mediumList.add("Telugu");
mediumList.add("English");
model.addAttribute("medium",mediumList);
List<String> sectionList =new ArrayList<String>();
sectionList.add("--Select--");
sectionList.add("A");
sectionList.add("B");
sectionList.add("C");
sectionList.add("D");
sectionList.add("E");
model.addAttribute("section", sectionList);
List<String> cityList=new ArrayList<String>();
cityList.add("--Select--");
cityList.add("Bangalore");
cityList.add("Hyderabad");
cityList.add("Chennai");
cityList.add("Mumbai");
model.addAttribute("city", cityList);
List<String> genderList =new ArrayList<String>();
//genderList.add("--Select--");
genderList.add("Male");
genderList.add("Female");
}
#SuppressWarnings("rawtypes")
#RequestMapping("/list")
public ModelAndView listStudents(){
List studentsList=studentService.listStudents();
return new ModelAndView("/list","studentsList",studentsList);
}
#RequestMapping("/delete")
public ModelAndView deleteStudent(#RequestParam Integer sid){
studentService.deleteStudent(sid);
return new ModelAndView("redirect:list");
}
#RequestMapping("/edit")
public ModelAndView editStudent(#RequestParam Integer sid){
Student studentObject=studentService.getStudent(sid);
return new ModelAndView("edit","studentObject",studentObject);
}
#RequestMapping("/update")
public ModelAndView updateSudent(#ModelAttribute Student student){
studentService.updateStudent(student);
return new ModelAndView("redirect:list");
}
}
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>School Management System</title>
<script type="text/javascript" src="${pageContext.servletContext.contextPath}/resources/js/hello.js"></script>
<script type="text/javascript" src="${pageContext.servletContext.contextPath}/resources/js/sms_validation.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.servletContext.contextPath}/resources/css/styles.css"/>
<script>
$(function() {
$( ".datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-MM-yy"
});
});
</script>
</head>
<body>
<div id="container">
<div id="header">
</div>
<div id="content">
<div class="content_heading">Student Registration Form</div>
<p>This is a paragraph</p>
<button type="button" onclick="myFunction()">Date</button>
<p id="demo"></p>
<form:form id="registerForm" modelAttribute="student" method="post" action="register" onsubmit="return validateForm()">
<fieldset>
<legend>Student Details:</legend>
<table class="form_table">
<tr><td><form:label path="sid">Studet Id</form:label></td>
<td><form:input path="sid" placeholder="Enter Student Id"/></td>
<td><form:errors path="sid" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="firstName">First Name</form:label></td>
<td><form:input path="firstName"/></td>
<td><form:errors path="firstName" cssClass="error"/></td>
</tr>
<tr><td><form:label path="lastName">Last Name</form:label></td>
<td><form:input path="lastName"/></td>
<td><form:errors path="lastName" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="middleName">Middle Name</form:label></td>
<td><form:input path="middleName"/></td>
<td><form:errors path="middleName" cssClass="error"/></td>
</tr>
<tr><td><form:label path="fatherName">Father Name</form:label></td>
<td><form:input path="fatherName"/></td>
<td><form:errors path="fatherName" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="motherName">Mother Name</form:label></td>
<td><form:input path="motherName"/></td>
<td><form:errors path="motherName" cssClass="error"/></td>
</tr>
<tr><td><form:label path="dateOfBirth">Date Of birth</form:label></td>
<td><form:input path="dateOfBirth" class="datepicker"/></td>
<td><form:errors path="dateOfBirth" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="admissionNo">Admission No</form:label></td>
<td><form:input path="admissionNo"/></td>
<td><form:errors path="admissionNo" cssClass="error"/></td>
</tr>
<tr><td><form:label path="dateOfJoining">DateOfJoining</form:label></td>
<td><form:input path="dateOfJoining" class="datepicker"/></td>
<td><form:errors path="dateOfJoining" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="standard">Standard</form:label></td>
<td><form:select path="standard" >
<form:options items="${standard}"/>
</form:select></td>
<td><form:errors path="standard" cssClass="error"/></td>
</tr>
<tr><td><form:label path="section">Section</form:label></td>
<td><form:select path="section" items="${section}"/></td>
<td><form:errors path="section" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="medium">Medium</form:label></td>
<td><form:radiobuttons path="medium" items="${medium}"/></td>
<td><form:errors path="medium" cssClass="error"/></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Addres Details:</legend>
<table class="form_table">
<tr><td><form:label path="address.doorNo">DoorNo</form:label></td>
<td><form:input path="address.doorNo"/></td>
<td><form:errors path="address.doorNo" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="address.streetName">StreetName</form:label></td>
<td><form:input path="address.streetName"/></td>
<td><form:errors path="address.streetName" cssClass="error"/></td>
</tr>
<tr><td><form:label path="address.addressLine">AddressLine</form:label></td>
<td><form:input path="address.addressLine"/></td>
<td><form:errors path="address.addressLine" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="address.city">City</form:label></td>
<td><form:select path="address.city" items="${city}"/></td>
<td><form:errors path="address.city" cssClass="error"/></td>
</tr>
<tr><td><form:label path="address.district">District</form:label></td>
<td><form:input path="address.district"/></td>
<td><form:errors path="address.district" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="address.state">State</form:label></td>
<td><form:input path="address.state"/></td>
<td><form:errors path="address.state" cssClass="error"/></td>
</tr>
<tr><td><form:label path="address.pin">Pin</form:label></td>
<td><form:input path="address.pin"/></td>
<td><form:errors path="address.pin" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="address.phone">Phone</form:label></td>
<td><form:input path="address.phone"/></td>
<td><form:errors path="address.phone" cssClass="error"/></td>
</tr>
<tr><td><form:label path="address.email">Email</form:label></td>
<td><form:input path="address.email"/></td>
<td><form:errors path="address.email" cssClass="error"/></td>
</tr>
<tr>
<td><form:label path="address.country">Country</form:label></td>
<td><form:input path="address.country"/></td>
<td><form:errors path="address.country" cssClass="error"/></td>
</tr>
<tr><td></td>
<td><input type="submit" value="Save"/></td><td></td>
</tr>
</table>
</fieldset>
</form:form>
</div>
<div id="footer"></div>
</div>
</body>
</html>
Please solve my problem ,Thanks in advance..
I think you will have to add below initbinder inside your controller,which will convert to the required format.
#InitBinder
public void initBinder(WebDataBinder binder) {
CustomDateEditor editor = new CustomDateEditor(new SimpleDateFormat("dd-MMMM-yy"), true);
binder.registerCustomEditor(Date.class, editor);
}
Also use below annotation for date field in Student class.
#DateTimeFormat(pattern = "dd-MMMM-yy")
private Date dateOfBirth;
#DateTimeFormat(pattern = "dd-MMMM-yy")
private Date dateOfJoining;
#DateTimeFormat(pattern = "dd-MMMM-yy")
private Date dateOfBirth;
#DateTimeFormat(pattern = "dd-MMMM-yy")
private Date dateOfJoining;
These Lines solved my problem... Thanks Mr. #RE350