Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
The deadly train derailment that occurred recently in DuPont, Washington, raises a lot of questions. It was a new route, the first trip tested with passengers, and the train was travelling at 50 mph over the zone’s speed limit. Could IoT play a role…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

580 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