File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes jsp vector problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "jsp vector problem" Watch "jsp vector problem" New topic
Author

jsp vector problem

kish ape
Greenhorn

Joined: Aug 13, 2001
Posts: 10
Hi,
I am using ms-sql database & accessing some data through java program in a jsp file.The java method returns Vector ,but the accessed data is too large can say 1000 at a time.So its not getting displayed all the items & also taking too much time.
So i want to divide that data into some parts while getting displayed.
Like 1st 50 then next 50 & so on..
(The way search engines displays the links)
Is it possible?
If yes then plz guide me for that
Thankx in advance
kshitija
DAYANAND BURAMSHETTY
Ranch Hand

Joined: Aug 06, 2001
Posts: 34
Hi,
I am sending three files.
If any problem let me know.
If I'm wrong ..correct me
//UserAdminServlet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import javax.ejb.FinderException;

public class UserAdminServlet extends HttpServlet{
private HttpSession session = null;
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void forward(HttpServletRequest req,HttpServletResponse res,String url)
throws ServletException, IOException{
res.setContentType("text/html");
RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
rd.forward(req, res);
}

public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{

/**
* (pages) This is for.... IF have 500 records then It display 1,2,3,4,5...10
*
*/
int pages=0;
/* *
* (dVector)This is dummy vector only 50( 0 to 49 or 50 to 99.. ..etc)
* records keep in this Vector and forward to the UserAdmin.jsp
* /
Vector dVector=null;
......
..............
/**
* All records are available in this(userVec)Vector ...everytime I take
* only 50 records from this Vector and stored in dummy Vector.
* contenetController(Write your own object for getting all records)
* is object from this I get all records.
*/
Vector userVec=contentController.getAllUserList();
/**
* Very first time call this servlet at that moment don't think
* about ORDER(Very first time It's NULL then It 1 to 50 records
* taking from userVec and stored in dummyVec and forward to the
* UserAdmin.jsp)
*/
String order=(String)req.getParameter("ORDER");
if(order==null){

dVector=new Vector();
pages=Math.round((dVector.size())/50);
for (Enumeration e = dVector.elements() ,int i=0; e.hasMoreElements(),i++ {
UserTB usertb=(UserTB)e.elementAt(i);
dVector.addElement(usertb);
if(i<50) break;
}
req.setAttribute("USERLIST", dVector);
req.setAttribute("PAGES", ""+pages);
this.forward(req,res,"/UserAdmin.jsp");
} else {
/** This block never excute very first time.
* First time display the (0-49 records) in UserAdmin.jsp and from that page
* we put index like 1,2,3...If click 2 It display the 50 - 99 records in that(UserAdmin.jsp)
* U put <a href="/UserAdminServlet?ORDER=2">2</a> It calls this servlet take the 50(10-99)
* records from userVec and keep into the dummyVector and forward to the UserAdmin.jsp
*/
int orderInt=(int)Integer.parseInt(order);
dVector=new Vector();
pages=Math.round((dVector.size())/50);
for (Enumeration e1 = dVector.elements() ,int i1=(orderInt-1)*50; e1.hasMoreElements(),i1++ {
UserTB usertb=(UserTB)e1.elementAt(i1);
dVector.addElement(usertb);
if(i1<((orderInt)*50)) break;
}
req.setAttribute("USERLIST", dVector);
req.setAttribute("PAGES", ""+pages);
this.forward(req,res,"/UserAdmin.jsp");

}

}//service
}

//UserTB.java
public class UserTB {
private String userName=null;
private String password=null;
...
pulic void setUserName(String userName){
this.userName=userName;
}
public void setPassword(String password){
this.password=password;
}
.....
public String getUserName(){
return userName;
}
public String getPassword(){
return passWord;
}
.....
}

//UserAdmin.jsp

<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page session = "true" %>
<%

userVec=(Vector)request.getAttribute("USERLIST");
int pages=(int)Integer.parseInt((String)request.getAttribute("PAGES"));
%>
<html>
<form NAME="admin" action="" METHOD="POST" >
<table width=100% border="1" cellspacing="2" cellpadding="5" >
<tr>

<th width="20%" class="adminhdr">User Name</th>
.......
</tr>

<%
for( Enumeration e=userVec.elements() ;e.hasMoreElements();i++){
UserTB usertb = null;
String userId=null;
usertb=(UserTB)e.nextElement();
userId=(String)usertb.getUserName();
....
%>
<tr>
<td width="20%" class="admin"> <%=userId%> </td>
</tr>
<%}%>
</table><br>
<%
//Here display index like 1,2,3,4.... if U click 1 it calls the servlet and the servlet take the records(0 -49) from
//servlet and forward to the this page.
for(int i=0;i<pages;i++){
%><a href="/UserAdminServlet?ORDER=<%=(i++)"><%=(i++)%></a>
}
%>
</form>
</body>
</html>

Dil se....,<BR>Dayanand<BR>0065-8839071(off)<BR>0065-7547034(Res0
kish ape
Greenhorn

Joined: Aug 13, 2001
Posts: 10
Hi!!!
Thankx for the help .
If any problem is there i will definately ask.
As i am not using servlets at all so i think i have to convert this logic in normal java prog.
I will try & let u know
bye
Originally posted by DAYANAND BURAMSHETTY:
Hi,
I am sending three files.
If any problem let me know.
If I'm wrong ..correct me
//UserAdminServlet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import javax.ejb.FinderException;

public class UserAdminServlet extends HttpServlet{
private HttpSession session = null;
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void forward(HttpServletRequest req,HttpServletResponse res,String url)
throws ServletException, IOException{
res.setContentType("text/html");
RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
rd.forward(req, res);
}

public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{

/**
* (pages) This is for.... IF have 500 records then It display 1,2,3,4,5...10
*
*/
int pages=0;
/* *
* (dVector)This is dummy vector only 50( 0 to 49 or 50 to 99.. ..etc)
* records keep in this Vector and forward to the UserAdmin.jsp
* /
Vector dVector=null;
......
..............
/**
* All records are available in this(userVec)Vector ...everytime I take
* only 50 records from this Vector and stored in dummy Vector.
* contenetController(Write your own object for getting all records)
* is object from this I get all records.
*/
Vector userVec=contentController.getAllUserList();
/**
* Very first time call this servlet at that moment don't think
* about ORDER(Very first time It's NULL then It 1 to 50 records
* taking from userVec and stored in dummyVec and forward to the
* UserAdmin.jsp)
*/
String order=(String)req.getParameter("ORDER");
if(order==null){

dVector=new Vector();
pages=Math.round((dVector.size())/50);
for (Enumeration e = dVector.elements() ,int i=0; e.hasMoreElements(),i++ {
UserTB usertb=(UserTB)e.elementAt(i);
dVector.addElement(usertb);
if(i<50) break;
}
req.setAttribute("USERLIST", dVector);
req.setAttribute("PAGES", ""+pages);
this.forward(req,res,"/UserAdmin.jsp");
} else {
/** This block never excute very first time.
* First time display the (0-49 records) in UserAdmin.jsp and from that page
* we put index like 1,2,3...If click 2 It display the 50 - 99 records in that(UserAdmin.jsp)
* U put <a href="/UserAdminServlet?ORDER=2">2</a> It calls this servlet take the 50(10-99)
* records from userVec and keep into the dummyVector and forward to the UserAdmin.jsp
*/
int orderInt=(int)Integer.parseInt(order);
dVector=new Vector();
pages=Math.round((dVector.size())/50);
for (Enumeration e1 = dVector.elements() ,int i1=(orderInt-1)*50; e1.hasMoreElements(),i1++ {
UserTB usertb=(UserTB)e1.elementAt(i1);
dVector.addElement(usertb);
if(i1<((orderInt)*50)) break;
}
req.setAttribute("USERLIST", dVector);
req.setAttribute("PAGES", ""+pages);
this.forward(req,res,"/UserAdmin.jsp");

}

}//service
}

//UserTB.java
public class UserTB {
private String userName=null;
private String password=null;
...
pulic void setUserName(String userName){
this.userName=userName;
}
public void setPassword(String password){
this.password=password;
}
.....
public String getUserName(){
return userName;
}
public String getPassword(){
return passWord;
}
.....
}

//UserAdmin.jsp

<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page session = "true" %>
<%

userVec=(Vector)request.getAttribute("USERLIST");
int pages=(int)Integer.parseInt((String)request.getAttribute("PAGES"));
%>
<html>
<form NAME="admin" action="" METHOD="POST" >
<table width=100% border="1" cellspacing="2" cellpadding="5" >
<tr>

<th width="20%" class="adminhdr">User Name</th>
.......
</tr>

<%
for( Enumeration e=userVec.elements() ;e.hasMoreElements();i++){
UserTB usertb = null;
String userId=null;
usertb=(UserTB)e.nextElement();
userId=(String)usertb.getUserName();
....
%>
<tr>
<td width="20%" class="admin"> <%=userId%> </td>
</tr>
<%}%>
</table><br>
<%
//Here display index like 1,2,3,4.... if U click 1 it calls the servlet and the servlet take the records(0 -49) from
//servlet and forward to the this page.
for(int i=0;i<pages;i++){
%><a href="/UserAdminServlet?ORDER=<%=(i++)"><%=(i++)%></a>
}
%>
</form>
</body>
</html>

 
Don't get me started about those stupid light bulbs.
 
subject: jsp vector problem
 
Similar Threads
Checkbox editor for JTable column
performance issue of Vector
Problem in refreshing the data..
Regarding JPanel
Passing transfer from servlet to JSP