Using package in JSP

Posted on 2005-02-28
Medium Priority
Last Modified: 2012-05-05

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">

  <TITLE>Color Testing</TITLE>

<%@ 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>

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++) {
Question by:dkim18
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 10

Accepted Solution

kupra1 earned 400 total points
ID: 13423551
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.
LVL 28

Expert Comment

ID: 13424772
>   bgColor = bgColor + Integer.toHexString(hw5.RanUtilities.randomInt(256));
Did you try ?
   bgColor = bgColor + Integer.toHexString(RanUtilities.randomInt(256));

Author Comment

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

thanks anyway

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question