Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can anybody solve this error

 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
  • 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 rax_india@yahoo.com
 
Hari Haran
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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
  • 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>

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic