Wrox Programmer Forums
BOOK: Beginning JavaServer Pages
This is the forum to discuss the Wrox book Beginning JavaServer Pages by Vivek Chopra, Jon Eaves, Rupert Jones, Sing Li, John T. Bell; ISBN: 9780764574856
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaServer Pages section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 19th, 2005, 08:09 PM
Registered User
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default resolutions issues


I'd like to help you with your current problems, but first of all I need to know if you've managed to get Tomcat setup and installed correctly. Many of the issues that you're describing can be a result of not having the basics done, and then trying to build on an unstable base.

First of all, make sure that the web container is installed correctly, and just try it with a really simple example (like a HelloWorld.jsp) with nothing special.

After you can successfully do that, then working on the more complicated examples will potentially be more successful.
Old May 20th, 2005, 11:48 AM
Registered User
Join Date: May 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts

I have Tomcat 5.5 installed and running - my localhost:8080/manager is working, and I've got chapter examples 1 and 2 working, and other than the fact that my "User" class is undefined, my war is being unpacked and used properly. Im using ant 1.6.2 to create the war file, and it's working properly between my index.jsp and my login page (named page.jsp)and other than my user isn't validating like I want it to, after the form is submitted in my login page, you are sent to the logged in page (named page2.jsp). I've also got the tomcat admin working (I had to download and set some things up seperatley for that) so I greatly doubt I have tomcat issues. My thought was that Im not doing classpath right with the war, or that I'm using a custom java class where I'm not allowed. Let me include my source.

******** here is my User.java ********
******** note that most is just code in getValid() for validation, and it complies to the javabean specifications ********

package com.custom;

import java.beans.*;
import java.util.*;

public class User extends Object implements java.io.Serializable {

    private String name = null;
    private String password = null;
    // Validation code
    private int valid = -1;
    // -1 -- FALSE -- Not yet validated -- only get this if major problem
    // (getValid does NOT simply return valid - it sets it to proper code)
    // See getValid comments for more details

    public User() {

    public void setName(String name) {
        this.name = name;

    public String getName() {
        return this.name;

    public void setPassword(String password) {
        this.password = password;

    // RETURNS: INT -- The code for the success or failure of validation
    // 0 -- TRUE -- It worked, correct name and password! YAY!
    // 1 -- FALSE -- No user name
    // 2 -- FALSE -- User name incorrect length. Minimum of 5 characters.
    // 3 -- FALSE -- User name incorrect length. Maximum of 30 characters.
    // 4 -- FALSE -- No password
    // 5 -- FALSE -- Password incorrect length. Minimum of 6 characters.
    // 6 -- FALSE -- Password incorrect length. Maximum of 10 characters.
    // 7 -- FALSE -- Password is incorrect for user name.
    public int getValid() {
        // Check if they have a valid user name
        // Did they enter a name? NO = 1
        if(this.name == null || this.name.length() == 0)
            return this.valid = 1;
        // Is the name a valid length? (5-30 characters) NO = 2 || 3
        if(this.name.length() < 5)
            return this.valid = 2;
        if(this.name.length() > 30)
            return this.valid = 3;
        // Check if they have a valid password
        // Did they enter a password? NO = 4
        if(this.password == null || this.password.length() == 0)
            return this.valid = 4;
        // Is the password a valid length? (6-10 characters) NO = 5 || 6
        if(this.password.length() < 6)
            return this.valid = 5;
        if(this.password.length() > 10)
            return this.valid = 6;
        // Now that we can check, lets make sure password is correct for name
        // NO = 7
            if(this.password.equals("Password") == false)
                return this.valid = 7;
            return this.valid = 7;

        // If you made it this far, you're in.
        return this.valid = 0;

******* here is page.jsp (log in page) ********

<%@ page language="java" import = "com.custom.*,java.util.*" %>

    <title>Log In</title>

      <script language="javascript" type="text/javascript">
        var nValid = -1;
        var stName = null;
        var stPassword = null;
        // This function overrides OnSubmit with my own validation
        function submitMe(){
          // Set up user and make sure I can access form objects
          var user = new User();
            alert("BUG: The form is not set properly.");
            return false;
            stName = document.forms["logIn"]["name"].value;
          else {
            alert("BUG: The form objects are not set properly.");
            return false;
            stPassword = document.forms["logIn"]["password"].value;
          else {
            alert("BUG: The form objects are not set properly.");
            return false;
          // I have form objects, time to set up user for validation
          // Time for validation, and alerts for problems
          if((nValid = user.getValid()) == 0)
            return true;
            case -1:
              alert("BUG: Problem accessing the form.");
              return false;
            // case 0 taken care of with prior if statement
            case 1:
              alert("You must enter a valid user name. User name is case sensitive.");
              return false;
            case 2:
              alert("User name incorrect length. Must be at least 5 characters.");
              return false;
            case 3:
              alert("User name incorrect length. Must be no more than 30 characters.");
              return false;
            case 4:
              alert("You must enter a valid password. Password is case sensitive.");
              return false;
            case 5:
              alert("Password incorrect length. Must be no less than 6 characters.");
              return false;
            case 6:
              alert("Password incorrect length. Must be no more than 10 characters.");
              return false;
            case 7:
              alert("Incorrect password for user name. Please try again.\nPassword is case

              return false;


      <form name="logIn" action="page2.jsp" method="POST" onsubmit="submitMe()">

        User Name:
        <input type="TEXT" name="name">
        <input type="PASSWORD" name="password">
        <input type="SUBMIT" value="Log In">

******** here is my build file and file stucture (has changed slightly) ******

ROOT = F:\Testing

| +---index.jsp(simply a header, and a link to page.jsp)
| +---page.jsp(included above)
| +---page2.jsp(simply a header)
| +---classes
| | +---com
| | +---custom
| | +---User.class(User.java included above)
| +---lib
| | +---jstl.jar
| | +---standard.jar
| +---image(2 in here, not used yet though - used in page2 later)
| +---web.xml(included below)
+Testing.war (when deployed, same structure as this)

** and here is build.xml **

<project name="Testing" default="warItUp" basedir="F:\Testing">
  <target name="warItUp">
    <war destfile="Testing.war" webxml="WEB-INF\web.xml">
      <zipfileset dir="main" prefix="main" excludes="*.nbattrs"/>
      <zipfileset dir="WEB-INF\image" prefix="WEB-INF\image"/>
      <lib dir="WEB-INF\lib"/>
      <classes dir="WEB-INF\classes\com\custom" prefix="WEB-INF\classes\com\custom" excludes=".nbattrs"/>

******** here is my web.xml ********

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

  Trying to get a war file together


******* There's everything - if you would like me to send the war file somewhere, I will be more than happy to do so. *******

Old May 20th, 2005, 02:52 PM
Registered User
Join Date: May 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts

I looked around, and tried to make a build file that works like how the book does it - I made some changes to the directory structure so that the source is in the right place. I still get the same problem with this build file.....

******** here is build file for "Testing2" same as Testing, but different directory structure and build file.... ********

<?xml version="1.0"?>

<project name="Testing2" default="all" basedir=".">
<property name="catalina.home" value="/Tomcat 5.5"/>
<property name="app.name" value="Testing2"/>
<property name="app.path" value="${app.name}"/>
<property name="src.home" value="${basedir}/src"/>
<property name="web.home" value="${basedir}/web"/>
<property name="docs.home" value="${basedir}/docs"/>
<property name="build.home" value="${basedir}/build"/>
<property name="dist.home" value="${basedir}/dist"/>
<property name="war.file" value="${dist.home}/${app.name}.war"/>

<target name="clean" description="Deletes the build and dist directories">
    <delete dir="${build.home}"/>
    <delete dir="${dist.home}"/>

<target name="prepare" description="Creates needed directories, and copies needed info">
    <mkdir dir="${build.home}"/>
    <mkdir dir="${build.home}/images"/>
    <mkdir dir="${build.home}/WEB-INF"/>
    <mkdir dir="${build.home}/WEB-INF/classes"/>

    <copy todir="${build.home}">
     <fileset dir="${web.home}"/>

<target name="compile" depends="prepare" description="Compiles java and places them in the correct place">
    <javac srcdir="${src.home}"
        <fileset dir="${web.home}/WEB-INF/lib" includes="*.jar"/>
        <pathelement location="${catalina.home}/common/classes"/>
        <fileset dir="${catalina.home}/common/endorsed" includes="*.jar"/>
        <fileset dir="${catalina.home}/common/lib" includes="*.jar"/>
        <pathelement location="${catalina.home}/shared/classes"/>
        <fileset dir="${catalina.home}/shared/lib" includes="*.jar"/>

    <copy todir="${build.home}/WEB-INF/classes">
     <fileset dir="${src.home}" excludes="**/*.java"/>
    <copy todir="${build.home}/WEB-INF/lib">
     <fileset dir="${web.home}/WEB-INF/lib"/>

<target name="dist" depends="compile" description="Create the War file">
    <mkdir dir="${dist.home}"/>
    <jar jarfile="${war.file}" basedir="${build.home}"/>

<target name="all" depends="clean, prepare, compile, dist"
    description="Does everything to build the application and war file"/>


******** end of build file ********

Im getting a good war file from this too, but I still get the browser error "line 11 'User' is undefined" when I submit the form, after I put the new war up on tomcat (it comes up as testing2 so there is no confusion between this and the older version)
Old May 22nd, 2005, 11:51 PM
Registered User
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Correct me if I'm wrong (which I often am). It looks like you are trying to use the User.class within the context of a javascript function. This will not work, as the classes are for the servlet container, and not for the browser.

Of course, I've not tried to download and run the actual code that you've typed in. I would also suspect that the error you are getting is from the Javascript console rather than the web container.

To do what you are trying to do here, you will need to create a Javascript object, rather than a Java object.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Background Image for Different Resolutions Andraw Pro VB 6 0 November 6th, 2008 12:00 PM
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
Screen resolutions larry Javascript How-To 7 July 21st, 2004 08:24 AM
Screen Resolutions Alaric VS.NET 2002/2003 3 October 9th, 2003 11:17 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.