Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning JavaServer Pages
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 19th, 2005, 08:09 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default resolutions issues

Hi,

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.
Reply With Quote
  #2 (permalink)  
Old May 20th, 2005, 11:48 AM
Registered User
 
Join Date: May 2005
Location: San Diego, CA, .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.name.equals("Nicole"))
            if(this.password.equals("Password") == false)
                return this.valid = 7;
        if(this.name.equals("Paige"))
            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.*" %>


<html>
  <head>
    <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();
          if(!document.forms["logIn"]){
            alert("BUG: The form is not set properly.");
            return false;
          }
          if(document.forms["logIn"]["name"])
            stName = document.forms["logIn"]["name"].value;
          else {
            alert("BUG: The form objects are not set properly.");
            return false;
          }
          if(document.forms["logIn"]["password"])
            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
          user.setName(stName);
          user.setPassword(stPassword);
          // Time for validation, and alerts for problems
          if((nValid = user.getValid()) == 0)
            return true;
          switch(nValid){
            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

sensitive.");
              return false;
          }
        }
      </script>

    </head>

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

        User Name:
        <br>
        <input type="TEXT" name="name">
        <br>
        Password:
         <br>
        <input type="PASSWORD" name="password">
        <br>
        <input type="SUBMIT" value="Log In">
      </form>
    </body>

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

ROOT = F:\Testing

Testing
+---META-INF
| +---MANIFEST.MF
+---main
| +---index.jsp(simply a header, and a link to page.jsp)
| +---page.jsp(included above)
| +---page2.jsp(simply a header)
+---WEB-INF
| +---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"/>
    </war>
  </target>
</project>


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

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

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

    <description>
  Trying to get a war file together
    </description>
    <display-name>WARRRRRRRRRRRRRRRRRRRRR!!!!!!!</display-name>

</web-app>


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

Reply With Quote
  #3 (permalink)  
Old May 20th, 2005, 02:52 PM
Registered User
 
Join Date: May 2005
Location: San Diego, CA, .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>


<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}"/>
    </copy>
</target>


<target name="compile" depends="prepare" description="Compiles java and places them in the correct place">
    <javac srcdir="${src.home}"
         destdir="${build.home}/WEB-INF/classes"
         debug="true">
     <classpath>
        <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"/>
     </classpath>
    </javac>

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


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


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

</project>

******** 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)
Reply With Quote
  #4 (permalink)  
Old May 22nd, 2005, 11:51 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.