Results 1 to 2 of 2
  1. #1
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default need help in displaying data from servlet,jsp

    Hello JavaProgrammers,
    i encountered with a problem in my web application
    when i try to display the records by using JSP page



    when i try to display the records by using JSP page it is throwing the below exception:

    HTTP Status 500 - java.util.NoSuchElementException

    type Exception report

    message java.util.NoSuchElementException

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: java.util.NoSuchElementException
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:549)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:470)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)
    displayrecord.doGet(displayrecord.java:52)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)
    root cause

    java.util.NoSuchElementException
    java.util.ArrayList$Itr.next(ArrayList.java:794)
    org.apache.jsp.displayrecord_jsp._jspService(displ ayrecord_jsp.java:108)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)
    displayrecord.doGet(displayrecord.java:52)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.34 logs.

    Apache Tomcat/7.0.34

    this is my display record servlet

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.util.ArrayList;
    import java.util.List;

    public class displayrecord extends HttpServlet {

    List lst= new ArrayList();
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
    Driver d= new org.apache.derby.jdbc.ClientDriver();
    DriverManager.registerDriver(d);
    Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/emp","root","root");
    PreparedStatement st=con.prepareStatement("select * from emp");
    ResultSet rs= st.executeQuery();
    while(rs.next()){
    lst.add(rs.getString("id"));
    lst.add(rs.getString("ename"));
    lst.add(rs.getString("des"));
    lst.add(rs.getString("sal"));
    }
    rs.close();
    }catch(Exception k)
    {
    out.print("error"+k);
    }
    finally{
    request.setAttribute("empData",lst);
    RequestDispatcher rd= request.getRequestDispatcher("/displayrecord.jsp");
    rd.forward(request,response);
    lst.clear();
    out.close();
    }
    }
    }




    this is my displayrecord jsp page:
    <%--
    Document : displayrecord
    Created on : 9 Sep, 2013, 7:35:23 PM
    Author : Sravan
    --%>

    <%@page import="java.util.*"%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <script type="text/javascript">
    function editRecord(id){
    url="EditRecord";
    window.location.href = "http://localhost:8084/myweb/"+url+"?id="+id;
    }
    function deleteRecord(id){
    url="DeleteRecord";
    window.location.href = "http://localhost:8084/myweb/"+url+"?id="+id;
    }



    </script>

    <table align="center">
    <%Iterator itr;%>
    <%List data = (List) request.getAttribute("empData");
    for(itr = data.iterator(); itr.hasNext();){
    %>
    <tr>
    <% String s = (String) itr.next();%>
    <td><%= s %></td>
    <td><%= itr.next() %></td>
    <td><%= itr.next() %></td>
    <td><%= itr.next() %></td>
    <td><input type="submit" value="edit" name ="edit" onclick ="editRecord (<%=s%>);"/></td>
    <td><input type="submit" value="delete" name ="delete" onclick ="deleteRecord (<%=s%>);"/></td>
    <%}%>
    </tr>
    </table>
    </body>
    </html>

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default Re: need help in displaying data from servlet,jsp

    Please don't double post on the forums.
    I'm closing this one as I answered in your other thread.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Need Help with storing and displaying data
    By Mitho in forum New To Java
    Replies: 5
    Last Post: 04-11-2012, 12:20 AM
  2. Replies: 3
    Last Post: 11-24-2011, 02:18 PM
  3. displaying database data in a gui
    By smallmos1 in forum New To Java
    Replies: 8
    Last Post: 03-22-2011, 01:21 PM
  4. Displaying results from the servlet to jsp web page
    By rushhour in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-17-2010, 01:13 PM
  5. Displaying Data
    By skiing in forum New To Java
    Replies: 4
    Last Post: 11-15-2008, 03:56 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •