Link to home
Start Free TrialLog in
Avatar of dkim18
dkim18

asked on

Using package in JSP

hi!

I am trying to use package, but when I run it, I have this error.

class file contains wrong class: java.lang.RuntimeException
Please remove or make sure it appears in the correct subdirectory of the classpath.
     bgColor = bgColor + Integer.toHexString(hw5.RanUtilities.randomInt(256));
                                                ^
1 error

I placed ColorTestOne.jsp under public_html dir and place RanUtilities.class under WEB-INF/classes/hw5/.
what did I do wrong?

This is ColorTestOne.jsp file
+++++++++++++++++++++++++++++++++++++++++++++=
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>
<HEAD>
  <TITLE>Color Testing</TITLE>
</HEAD>

<%@ page import="hw5.RanUtilities" %>

<%!

private String ramdonColor(){

  String bgColor="";
  for(int i=0; i < 3; i++){  
     bgColor = bgColor + Integer.toHexString(hw5.RanUtilities.randomInt(256));
  }
   return "#"+bgColor;
}

%>

<%
String bgColor = request.getParameter("bgColor");
if ((bgColor == null) || (bgColor.trim().equals(""))) {
  bgColor = "WHITE";
}
%>

<BODY BGCOLOR="<%= ramdonColor() %>">
<H2 ALIGN="CENTER">Testing a Background of "<%= ramdonColor() %>"</H2>
</BODY></HTML>


this is RanUtilities.java file
+++++++++++++++++++++++++++

package hw5;

public class RanUtilities {

  /** A random int from 1 to range (inclusive). */

  public static int randomInt(int range) {
    return(1 + ((int)(Math.random() * range)));
  }

  public static void main(String[] args) {
    int range = 10;
    try {
      range = Integer.parseInt(args[0]);
    } catch(Exception e) { // Array index or number format
      // Do nothing: range already has default value.
    }
    for(int i=0; i<100; i++) {
      System.out.println(randomInt(range));
    }
  }
}
ASKER CERTIFIED SOLUTION
Avatar of kupra1
kupra1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rrz
>   bgColor = bgColor + Integer.toHexString(hw5.RanUtilities.randomInt(256));
Did you try ?
   bgColor = bgColor + Integer.toHexString(RanUtilities.randomInt(256));
Avatar of dkim18
dkim18

ASKER

I put it in other pkg and it worked even witout <%@ page import="hw5.RanUtilities" %>.
I don't know why...

thanks anyway