• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

can anybody solve this error

 
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i,am trying to call a vector with 3 elements stored in it which i've created in a bean and calling it into jsp ......the prob is that i,am getting an error :---javax.servlet.ServletException: Cannot create bean of class proj2.try1.
plz ....help me
my e-mail is [email protected]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried working on ur problem and it seems to create no probs.
Here is the sample code.
I used a javawebserver.
Place the compiled bean class file under the \classes\sunexamples\beans folder
Jsp under \public_html folder
Happy Coding!!!

Bean
=====
package sunexamples.beans;
import java.util.*;
public class myclass
{
public Vector v=new Vector();
public Vector getVector()
{
try
{
v.add("Java");
v.add("Ranch");
v.add("Servlets and JSps");
return v;
}
catch(Exception e)
{
return null;
}
}
}
Jsp
====
<%@ page language="java" import="java.util.*" %>
<jsp:useBean id="mc" scope="session" class="sunexamples.beans.myclass" />
<html>
<body>
<%
try
{
Vector vtr=mc.getVector();
String s;
out.println(vtr);
if(vtr!=null)
{
Enumeration enum= vtr.elements();
out.println("I am here");
while (enum.hasMoreElements())
{
s= (String) enum.nextElement();
out.println(s);
}
}
else
{
out.println("Vector is Null");
}
}
catch(Exception e)
{
out.println("Error"+e);
}
%>
</body>
</html>
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
ive worked on this prob ...no output ...still the same ....here is the code .
package rax;
import java.util.*;
public class try1
{
public String itemno;
public String itemprice;
public int itemid;
public String[]itemids;
public int i;
public Vector items = new Vector() ;
public try1(String itemno , String itemprice , int itemid)
{
items.addElement(new try1("0","raghav",20));
items.addElement(new try1("1","raxy" ,30));
items.addElement(new try1("2","rexy",40));
}
/*
this.itemno=itemno;
this.itemprice=itemprice;
this.itemid=itemid;
}
*/
/* the methods starts here
*/
synchronized public Vector getItems1()
{
items.addElement(new try1("0","raghav",20));
items.addElement(new try1("1","raxy" ,30));
items.addElement(new try1("2","rexy",40));

for(int i=0;i<items.size();i++)
{
items.get(i);
}
return items;
}
public void setItems()
{
this.items=items;
}
public String getItemno()
{
return itemno;
}
public void setItemno()
{
this.itemno=itemno;
}
public String getItemprice()
{
return itemprice;
}
public void setItemprice()
{
this.itemprice=itemprice;
}
public int getItemid()
{
return itemid;
}
public void setItemid()
{
this.itemid=itemid;
}
public try1 getItem(String itemid)
{
int index=Integer.parseInt(itemid);
return (try1) items.elementAt(index);
}

public String[] getItemids()
{
return itemids;
}
public void setItemids()
{
this.itemids=itemids;
}
public String toString()
{
return itemid +itemno + itemprice ;
}
}

Originally posted by Hari Haran:
I tried working on ur problem and it seems to create no probs.
Here is the sample code.
I used a javawebserver.
Place the compiled bean class file under the \classes\sunexamples\beans folder
Jsp under \public_html folder
Happy Coding!!!

Bean
=====
package sunexamples.beans;
import java.util.*;
public class myclass
{
public Vector v=new Vector();
public Vector getVector()
{
try
{
v.add("Java");
v.add("Ranch");
v.add("Servlets and JSps");
return v;
}
catch(Exception e)
{
return null;
}
}
}
Jsp
====
<%@ page language="java" import="java.util.*" %>
<jsp:useBean id="mc" scope="session" class="sunexamples.beans.myclass" />
<html>
<body>
<%
try
{
Vector vtr=mc.getVector();
String s;
out.println(vtr);
if(vtr!=null)
{
Enumeration enum= vtr.elements();
out.println("I am here");
while (enum.hasMoreElements())
{
s= (String) enum.nextElement();
out.println(s);
}
}
else
{
out.println("Vector is Null");
}
}
catch(Exception e)
{
out.println("Error"+e);
}
%>
</body>
</html>


 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic