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));
    }
  }
}
dkim18Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kupra1Commented:
It should work. Nevertheless, check whether your classpath are set to the /WEB-INF/classes. If your configurations are all correct, you should not even need to set the above.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrzCommented:
>   bgColor = bgColor + Integer.toHexString(hw5.RanUtilities.randomInt(256));
Did you try ?
   bgColor = bgColor + Integer.toHexString(RanUtilities.randomInt(256));
0
dkim18Author Commented:
I put it in other pkg and it worked even witout <%@ page import="hw5.RanUtilities" %>.
I don't know why...

thanks anyway
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.