• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How will u generate random numbers in jsp and using jsp bean

 
karai baskar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code works well with jvm.but it fails to answer when the same code is used a jsp bean
The following is bean file
package rand;
import java.util.Random;
public class rand {
int b;
Random r=new Random();

public rand(){
b=r.nextInt(7);
}
public int getrand(){
return b;
}
public static void main(String arg[]){
rand r=new rand();
System.out.println(r.getrand());
}
}
The following is jsp file
<%@ page import="java.util.Random" %>
<%
java.util.Random r=new java.util.Random(7);
int i=r.nextInt();
out.println(i);
%>
it gives the following error
Error during JSP page processing
java.lang.NoSuchMethodError: java.util.Random: method nextInt(I)I not found
Pls solve the above problem as quick as possible
 
Sarath Mohan
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You want to use that class as a bean in JSP.
then your code is wrong.
You should use the <jsp:useBean /> tag.
Pl. refer a JSP book,
Binu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic