javascript - How to display "no result found" using arraylist in struts2 -
here firing query ..and displays record want if there no record should display "no match/result found" .
using arraylist in struts2 . can able achieve ? please if can make changes or suggest helpful. have searched solution wasn't able relevant solution. below posting action class , jsp page on want display results.
in advance. :)
booksearchaction.java
package org.entity; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.statement; import java.util.arraylist; import java.util.list; import com.opensymphony.xwork2.actionsupport; public class booksearchaction extends actionsupport { book book; list<book> bookresultlist; public book getbook() { return book; } public void setbook(book book) { this.book = book; } public list<book> getbookresultlist() { return bookresultlist; } public void setbookresultlist(list<book> bookresultlist) { this.bookresultlist = bookresultlist; } public booksearchaction() { // todo auto-generated constructor stub } @override public string execute() throws exception { try { class.forname("com.mysql.jdbc.driver"); connection con = drivermanager.getconnection( "jdbc:mysql://localhost:3306/staff", "root", "siddheshkk"); system.out.println("driver loaded"); statement stmt = con.createstatement(); resultset rs = stmt .executequery("select * books12 name '%" + book.getbookname() + "%'"); bookresultlist = new arraylist<book>(); while (rs.next()) { bookresultlist.add(new book(rs.getstring(1), rs.getint(2))); } con.close(); } catch (exception e) { system.out.println(e); } return "success"; } } success.jsp
<%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <%@ taglib uri="/struts-tags" prefix="s"%> <!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>results</title> </head> <body> <h1>data retrieved successfully..</h1> <h3>here data: </h3><br> <table border="2"> <th> <tr><td>book name</td><td>cost</td></tr> </th> <s:iterator value="bookresultlist"> <s:iterator> <tr> <td><s:property value="bookname"/></td> <td><s:property value="bookcost"/></td> </tr> </s:iterator> </s:iterator> </table> </body> </html> anyone please me :(
you can use <s:if> , <s:else> tags of struts2 check whether list empty or not, example
<s:if test="%{bookresultlist.size>0}"> <table> <s:iterator value="bookresultlist"> <tr> <td><s:property value="bookname"/></td> <td><s:property value="bookcost"/></td> </tr> </s:iterator> </table> </s:if> <s:else> <div> no data found</div> </s:else> in case struts1.x version, can use <logic:present> tag. hope helps.
Comments
Post a Comment