Link to home
Start Free TrialLog in
Avatar of CharleneS77
CharleneS77Flag for United States of America

asked on

How do I deploy and run this JSP Web Application locally?

I am using Tomcat 6.0 through port 8282.  My operating system is Windows XP.  I am able to deploy and run other JSP Web Applications without errors.  The attached (zipped) folder is located at I:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ on my local machine.  When I attempt to deploy and run the attached JSP Web Application locally (http://localhost:8282/DistanceCalculator2/distanceCalculator2.jsp), I get the error below.  What is causing this error?  Thank you in advance!  

Note:  I have added .txt extensions to the end of each file because the other filetypes (.jsp, .java, and .class) are not able to be uploaded here.
HTTP Status 500 - 
 
--------------------------------------------------------------------------------
 
type Exception report
 
message 
 
description The server encountered an internal error () that prevented it from fulfilling this request.
 
exception 
 
javax.servlet.ServletException: java.lang.NoClassDefFoundError: calc/DistanceCalc2 (wrong name: DistanceCalc2)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:274)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Open in new window

DistanceCalculator2.zip
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CharleneS77

ASKER

Thank you for the response and the positive words.  I am now able to access my jsp, but when I click the Calculate button, I get the error below.  My latest version is attached.
HTTP Status 404 - /DistanceCalculator2/DistanceCalculator2.jsp
 
--------------------------------------------------------------------------------
 
type Status report
 
message /DistanceCalculator2/DistanceCalculator2.jsp
 
description The requested resource (/DistanceCalculator2/DistanceCalculator2.jsp) is not available.

Open in new window

DistanceCalculator2.zip
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If I use
<form method="post" action="distanceCalculator2.jsp">  
nothing happens when I click on the Calculate button.

If I use
<form method="post">  
nothing happens when I click on the Calculate button.
>nothing happens when I click on the Calculate button.  
What do you mean by "nothing" ?  Does the form submit a request ? No error mesages ?  If you change to
action="someOtherPage.jsp"  
does it go there ?
>>>What do you mean by "nothing" ?  
When I click the Calculate button, no output is displayed.

>>>Does the form submit a request ?
How do I determine whether a request was submitted?

>>>No error mesages ?
No error messages.

>>>>If you change to action="someOtherPage.jsp" does it go there ?
Yes, I moved currentTime.jsp to the same directory and it did go to currentTime.jsp.
>When I click the Calculate button, no output is displayed.  
Is there anything in the page source in the browser ?  
When I right click on the page and select View Source, I see the following:

 
 
 
 
 
<html>
	<head><title>JSP Distance Calculator using EL Statements, JSTL, and a JavaBean</title> </head>
	<body>
		<font face="Verdana"><center><i>
		<h1>JSP Distance Calculator using EL Statements, JSTL, and a JavaBean</h1>
		</i></center></font>
	
		<form method="post" action="distanceCalculator2.jsp">
			<br>
			<font size="2" face="Verdana">
			Please enter the value of X1:
			<font color="blue">*</font>
			<input type="text" name="x1" length="7"/>		
			<br>
			</font>
 
			<font size="2" face="Verdana">
			Please enter the value of Y1:
			<font color="blue">*</font>
			<input type="text" name="y1" length="7"/>		
			<br>
			</font>
 
			<font size="2" face="Verdana">
			Please enter the value of X2:
			<font color="blue">*</font>
			<input type="text" name="x2" length="7"/>		
			<br>
			</font>
 
			<font size="2" face="Verdana">
			Please enter the value of Y2:
			<font color="blue">*</font>
			<input type="text" name="y2" length="7"/>		
			</font>
 
			<p>
			<input type="submit" value="Calculate"/>
			</p>
		</form>
 
		
			
 
			
 
			
 
			
 
			
				
	</body>
</html>

Open in new window

I copy and pasted your last post and it displays in my browser(IE 7). You still see nothing in your browser window ?
>>>>I copy and pasted your last post and it displays in my browser(IE 7). You still see nothing in your browser window ?

Did you copy and paste the html that I got from View Source?  Are you able to get  result for the distance between the two points?  How?
>Did you copy and paste the html that I got from View Source?  
Yes.
>Are you able to get  result for the distance between the two points?  How?  
I didn't test that yet.
meanwhile add this inside your <c:choose> tag  
<c:otherwise>
                         something is wrong, I'll keep looking
</c:othewise>
no add this
<c:otherwise>
                     rrz${distance2.status}rrz
</c:othewise>
When I added the <c:otherwise> tag after the last <c:when> tag, and inside the <c:choose> tag, I get the following error:
HTTP Status 500 - 
 
--------------------------------------------------------------------------------
 
type Exception report
 
message 
 
description The server encountered an internal error () that prevented it from fulfilling this request.
 
exception 
 
org.apache.jasper.JasperException: /distanceCalculator2.jsp(94,3) The end tag "&lt;/c:othewise" is unbalan

Open in new window

try again with my last post
I still get the same error:

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /distanceCalculator2.jsp(94,3) The end tag "&lt;/c:othewise" is unbalanced


Below is what I have in the <c:choose> tag:
		<c:choose>
			<c:when test="${distance2.status == -1}">
				<hr/>
				Please input a value for X1.
			</c:when>
 
			<c:when test="${distance2.status == -2}">
				<hr/>
				Please input a value for Y1.
			</c:when>
 
			<c:when test="${distance2.status == -3}">
				<hr/>
				Please input a value for X2.
			</c:when>
 
			<c:when test="${distance2.status == -4}">
				<hr/>
				Please input a value for Y2.
			</c:when>
 
			<c:when test="${distance2.status == 1}">
				<hr/>
				<font face="Verdana"> <u>
				<h3> Output</h3>
				</u> </font>
 
				<font size="2" face="Verdana">
				X1 = ${distance2.x1} <br>
				Y1 = ${distance2.y1} <br>
				X2 = ${distance2.x2} <br>
				Y2 = ${distance2.y2} <br>
				</font>
 
				<br>
				<font size="3" face=Verdana" color="blue"> <b>
				The distance between (X1, Y1) and (X2, Y2) is 
				<fmt:formatNumber value="${distance2.distanceBetweenPoints}" 
						type="number" 
						maxFractionDigits="2"/>
			</c:when>
			<c:otherwise>
                     			rrz${distance2.status}rrz
			</c:othewise>
		</c:choose>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>>>I made a typo

Sorry I didn't catch that one.  Now I am seeing the same thing:  I have the page, I am able to input the values, I click the Calculate button, and nothing happens.  The only difference I see is the following at the bottom of the page, below the Calculate button:  rrz()rrz.  This is displayed before I click the Calculate button the first time.
Is it something in the JavaBean?  Are my setDistanceBetweenPoints( ) and calculateDistance( ) methods ok?
I guess I will try your web app in my Tomcat now.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK, I have added the web.xml file you posted.  I wonder why I do not get that error.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When I run this I get the following error:

HTTP Status 500 - 
 
--------------------------------------------------------------------------------
 
type Exception report
 
message 
 
description The server encountered an internal error () that prevented it from fulfilling this request.
 
exception 
 
org.apache.jasper.JasperException: /distanceCalculator2.jsp(3,0) The value for the useBean class attribute calc.DistanceCalc2 is invalid.

Open in new window

Nevermind, I have it working.
What am I missing to display my output in the <c:choose> tag?
>What am I missing to display my output in the <c:choose> tag?  
The output is displayed for me. What problem are you having with it ?  
I have most of it figured out now.  I do have one more problem though.  

With a call to calculateDistance( ); inside the getDistanceBetweenPoints( ) method, I am able to get a result for distanceBetweenPoints, but I am NOT able to check for user input.

Without a call to calculateDistance( ); inside the getDistanceBetweenPoints( ) method, I am able to check for user input, but I am NOT able to get a result for distanceBetweenPoints.  

My most recent code is here:

// The JavaBean
// DistanceCalc2.java
 
package calc;
 
public class DistanceCalc2
{      
	// read-write properties
   private String x1;
   private String y1;
   private String x2;
   private String y2;
            
   // read-only properties
   private double distanceBetweenPoints;
    
  
	// default constructor
   //-----------------------------------------  
	public DistanceCalc2( )
	{
		
	}
   //-----------------------------------------  
		            
   // setter and getter methods
   //-----------------------------------------      
   public void setX1( String passedX1 )
   {
   	x1 = passedX1;
   }
   //-----------------------------------------            
   public String getX1( )
   {
      return x1;	
   }
   //-----------------------------------------      
   public void setY1( String passedY1 )
   {
   	y1 = passedY1;
   }      
   //-----------------------------------------            
   public String getY1( )
   {
   	return y1;
   }
   //-----------------------------------------            
   public void setX2( String passedX2 )
   {
         x2 = passedX2;
   }      
   //-----------------------------------------            
   public String getX2( )
   {
      return x2;
   }
   //-----------------------------------------            
   public void setY2( String passedY2 )
   {
  		y2 = passedY2;
   }      
   //-----------------------------------------            
   public String getY2( )
   {
  		return y2;
   }  
   //-----------------------------------------  
   public void setDistanceBetweenPoints( )
   {
   	calculateDistance( );
   } 
   //-----------------------------------------		    
   public double getDistanceBetweenPoints( )
   {
		//calculateDistance( );
     	return distanceBetweenPoints;
   }      
   //-----------------------------------------                  
   private void calculateDistance( )
   {
			
		distanceBetweenPoints = Math.sqrt( ( Double.parseDouble( x1 ) - Double.parseDouble( x2 ) ) * 
                                         ( Double.parseDouble( x1 ) - Double.parseDouble( x2 ) ) + 
                                         ( Double.parseDouble( y1 ) - Double.parseDouble( y2 ) ) * 
                                         ( Double.parseDouble( y1 ) - Double.parseDouble( y2 ) ) );		
	}
}
 
 
 
<%-- distanceCalculator2.jsp --%>
 
<jsp:useBean id="distance2" scope="page" class="calc.DistanceCalc2" />
<jsp:setProperty name="distance2" property="*" />
 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
 
<html>
      <head><title>JSP Distance Calculator using EL Statements, JSTL, and a JavaBean</title> </head>
      <body>
      	<font face="Verdana"><center><i>
            	<h1>JSP Distance Calculator using EL Statements, JSTL, and a JavaBean</h1>
            	</i></center></font>
 
	<c:set var="x1" value="${distance2.x1}"/>
	<c:set var="y1" value="${distance2.y1}"/>
	<c:set var="x2" value="${distance2.x2}"/>
	<c:set var="y2" value="${distance2.y2}"/>
	<c:set var="distanceBetweenPoints" value="${distance2.distanceBetweenPoints}"/>
 
 
            	<form method="post" action="distanceCalculator2.jsp"/>
                  	<br>
                  	<font size="2" face="Verdana">
                  	Please enter the value of X1:
                  	<font color="blue">*</font>
                  	<input type="text" name="x1" length="7"/>            
              	    	<br>
                  	</font>
 
                  	<font size="2" face="Verdana">
                  	Please enter the value of Y1:
                  	<font color="blue">*</font>
                  	<input type="text" name="y1" length="7"/>            
                  	<br>
                  	</font>
 
                  	<font size="2" face="Verdana">
                  	Please enter the value of X2:
                  	<font color="blue">*</font>
                  	<input type="text" name="x2" length="7"/>            
                  	<br>
                  	</font>
 
                  	<font size="2" face="Verdana">
                  	Please enter the value of Y2:
                  	<font color="blue">*</font>
                  	<input type="text" name="y2" length="7"/>            
                  	</font>
 
                  	<p>
                  	<input type="submit" value="Calculate"/>
                  	</p>
            	</form>
 
	<c:if test="${pageContext.request.method=='POST'}">
            	<c:choose>
                  	<c:when test='${x1 == null}'>
                        		<hr/><br/>
			<font size="4" face=Verdana" color="red">
                        		Please input a value for X1.
			</font>
                  	</c:when>
 
                  	<c:when test='${y1 == null}'>
                        		<hr/><br/>
			<font size="4" face=Verdana" color="red">
                        		Please input a value for Y1.
			</font>
                  	</c:when>
 
                  	<c:when test='${x2 == null}'>
                        		<hr/><br/>
			<font size="4" face=Verdana" color="red">
                        		Please input a value for X2.
			</font>
                  	</c:when>
 
                  	<c:when test='${y2 == null}'>
                        		<hr/><br/>
			<font size="4" face=Verdana" color="red">
                        		Please input a value for Y2.
			</font>
                  	</c:when>
	
		<c:otherwise>
                                   	<hr/>
                        		<font face="Verdana"> <u>
                        		<h3>Output</h3>
                        		</u></font>
 
                        		<font size="4" face="Verdana" color="blue">
                        		X1 = ${x1} <br/>
                        		Y1 = ${y1} <br/>
                        		X2 = ${x2} <br/>
                        		Y2 = ${y2} <br/>
                        		</font>
 
                        		<br/><br/>
                        		<font size="4" face="Verdana" color="blue"> 
                        		The distance between (X1, Y1) and (X2, Y2) is 
                        		<fmt:formatNumber value="${distanceBetweenPoints}" 
                                    	type="number" maxFractionDigits="15"/> 
			</font>
                  	</c:otherwise>
            	</c:choose>
	</c:if>
 
	<font size="4" face="Verdana" color="green">
	<br/>
	<br/>
        	x1=${x1} 
	<br/>
	y1=${y1} 
	<br/>
	x2=${x2} 
	<br/>
	y2=${y2}
	<br/>
        	distanceBetweenPoints=${distanceBetweenPoints}
	<br/>
	</font>
 
      </body>
</html>

Open in new window

I got that part now.  My getDistanceBetweenPoints( ) method now looks like this:

   public double getDistanceBetweenPoints( )
   {
            if( ( x1 != null ) && ( y1 != null ) && ( x2 != null ) && ( y2 != null ) )
            {
                  calculateDistance( );
            }
           return distanceBetweenPoints;
   }

I know you recommended exception handling for letters being input.  Where would I put the exception?
Do I need to use the <%@ page errorPage> directive to handle the exception?



SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I did redesign.  I got rid of the status variable altogether.  Below is my latest code including my attempt at exception handling.  


// The JavaBean
// DistanceCalc2.java
 
package calc;
 
public class DistanceCalc2
{      
	// read-write properties
   private String x1;
   private String y1;
   private String x2;
   private String y2;
            
   // read-only properties
   private double distanceBetweenPoints;
	private String errorMessage;
    
  
	// default constructor
   //-----------------------------------------  
	public DistanceCalc2( )
	{
		
	}
   //-----------------------------------------  
		            
   // setter and getter methods
   //-----------------------------------------      
   public void setX1( String passedX1 )
   {
   	x1 = passedX1;
   }
   //-----------------------------------------            
   public String getX1( )
   {
      return x1;	
   }
   //-----------------------------------------      
   public void setY1( String passedY1 )
   {
   	y1 = passedY1;
   }      
   //-----------------------------------------            
   public String getY1( )
   {
   	return y1;
   }
   //-----------------------------------------            
   public void setX2( String passedX2 )
   {
         x2 = passedX2;
   }      
   //-----------------------------------------            
   public String getX2( )
   {
      return x2;
   }
   //-----------------------------------------            
   public void setY2( String passedY2 )
   {
  		y2 = passedY2;
   }      
   //-----------------------------------------            
   public String getY2( )
   {
  		return y2;
   }  
   //-----------------------------------------  
   public void setDistanceBetweenPoints( )
   {
   	calculateDistance( );
   } 
   //-----------------------------------------		    
   public double getDistanceBetweenPoints( )
   {
		if( ( x1 != null ) && ( y1 != null ) && ( x2 != null ) && ( y2 != null ) )
		{
			try 
			{
            Double.parseDouble( x1 );
            Double.parseDouble( y1 );
				Double.parseDouble( x2 );
            Double.parseDouble( y2 );
        	} 
			catch ( NumberFormatException nfe ) 
			{
            errorMessage = "Please enter a valid number: " + nfe.getMessage( );	
				setErrorMessage( errorMessage );
        	} 
			catch ( Exception e ) 
			{
           	errorMessage = "An error occured: " + e.getMessage( );
				setErrorMessage( errorMessage );
        	}
			
			calculateDistance( );
		}
     	return distanceBetweenPoints;
   }      
   //-----------------------------------------
   public void setErrorMessage( String passedErrorMessage )
   {
   	errorMessage = passedErrorMessage;
   }	
   //-----------------------------------------  
   public String getErrorMessage( )
   {
   	return errorMessage;
   } 
   //-----------------------------------------                  
   private void calculateDistance( )
   {			
		distanceBetweenPoints = Math.sqrt( ( Double.parseDouble( x1 ) - Double.parseDouble( x2 ) ) * 
                                         ( Double.parseDouble( x1 ) - Double.parseDouble( x2 ) ) + 
                                         ( Double.parseDouble( y1 ) - Double.parseDouble( y2 ) ) * 
                                         ( Double.parseDouble( y1 ) - Double.parseDouble( y2 ) ) );		
	}
}
  
//===================================
//===================================
 
<%-- distanceCalculator2.jsp --%>
 
<jsp:useBean id="distance2" scope="page" class="calc.DistanceCalc2" />
<jsp:setProperty name="distance2" property="*" />
 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
 
<html>
      <head><title>JSP Distance Calculator using EL Statements, JSTL, and a JavaBean</title> </head>
      <body>
	<br/>
      	<font face="Verdana"><center><i>
            	<h2>JSP Distance Calculator using EL Statements, JSTL, and a JavaBean</h2>
            	</i></center></font>
 
	<c:set var="x1" value="${distance2.x1}"/>
	<c:set var="y1" value="${distance2.y1}"/>
	<c:set var="x2" value="${distance2.x2}"/>
	<c:set var="y2" value="${distance2.y2}"/>
	<c:set var="distanceBetweenPoints" value="${distance2.distanceBetweenPoints}"/>
	<c:set var="errorMessage" value="${distance2.errorMessage}"/>
 
 
            	<form method="post" action="distanceCalculator2.jsp">
                  	<br>
                  	<font size="2" face="Verdana">
                  	Please enter the value of X1:
                  	<font color="blue">*</font>
                  	<input type="text" name="x1" length="7"/>            
              	    	<br>
                  	</font>
 
                  	<font size="2" face="Verdana">
                  	Please enter the value of Y1:
                  	<font color="blue">*</font>
                  	<input type="text" name="y1" length="7"/>            
                  	<br>
                  	</font>
 
                  	<font size="2" face="Verdana">
                  	Please enter the value of X2:
                  	<font color="blue">*</font>
                  	<input type="text" name="x2" length="7"/>            
                  	<br>
                  	</font>
 
                  	<font size="2" face="Verdana">
                  	Please enter the value of Y2.
                  	<font color="blue">*</font>
                  	<input type="text" name="y2" length="7"/>            
                  	</font>
 
                  	<p>
                  	<input type="submit" value="Calculate"/>
                  	</p>
            	</form>
 
	<c:if test="${pageContext.request.method=='POST'}">
            	<c:choose>
                  	<c:when test='${x1 == null}'>
                        		<hr/><br/>
			<font size="4" face="Verdana" color="red">
                        		You did not enter a value for X1.
			</font>
                  	</c:when>
 
                  	<c:when test='${y1 == null}'>
                        		<hr/><br/>
			<font size="4" face="Verdana" color="red">
                        		You did not enter a value for X1.
			</font>
                  	</c:when>
 
                  	<c:when test='${x2 == null}'>
                        		<hr/><br/>
			<font size="4" face="Verdana" color="red">
                        		You did not enter a value for X1.
			</font>
                  	</c:when>
 
                  	<c:when test='${y2 == null}'>
                        		<hr/><br/>
			<font size="4" face="Verdana" color="red">
                        		You did not enter a value for X1.
			</font>
                  	</c:when>
 
		<c:otherwise>
                                   	<hr/>
                        		<font face="Verdana"> <u>
                        		<h3>Output</h3>
                        		</u></font>
 
                        		<font size="4" face="Verdana" color="blue">
                        		X1 = ${x1} <br/>
                        		Y1 = ${y1} <br/>
                        		X2 = ${x2} <br/>
                        		Y2 = ${y2} <br/>
                        		</font>
 
 
 
 
			<c:choose>
				<c:when test='${errorMessage != null}'>
					<br/>
					<font size="4" face="Verdana" color="red">
                        				${errorMessage}
					</font>
				</c:when>
			
				<c:otherwise>
                        				<br/>
                        				<font size="4" face="Verdana" color="blue"> 
                        				The distance between (X1, Y1) and (X2, Y2) is 
                        				<fmt:formatNumber value="${distanceBetweenPoints}" 
                                    			type="number" maxFractionDigits="15"/> 
				</font>
				</c:otherwise>
			</c:choose>
 
 
 
                  	</c:otherwise>
            	</c:choose>
	</c:if>
	
	<%--
	<font size="4" face="Verdana" color="green">
	<br/><br/>
        	x1=${x1} 
	<br/>
	y1=${y1} 
	<br/>
	x2=${x2} 
	<br/>
	y2=${y2}
	<br/>
        	distanceBetweenPoints=${distanceBetweenPoints}
	<br/>
	</font>
	--%>
 
      </body>
</html>

Open in new window

OK, it works like a charm.  Thank you very much for taking the time to help me.  Below is the working code:
// The JavaBean
// DistanceCalc2.java
 
package calc;
 
public class DistanceCalc2
{      
	// read-write properties
   private String x1;
   private String y1;
   private String x2;
   private String y2;
            
   // read-only properties
   private double distanceBetweenPoints;
   private int status = 0;
  
	// default constructor
   //-----------------------------------------  
	public DistanceCalc2( )
	{
		
	}
   //-----------------------------------------  
		            
   // setter and getter methods
   //-----------------------------------------      
   public void setX1( String passedX1 )
   {
   	x1 = passedX1;
   }
   //-----------------------------------------            
   public String getX1( )
   {
      return x1;	
   }
   //-----------------------------------------      
   public void setY1( String passedY1 )
   {
   	y1 = passedY1;
   }      
   //-----------------------------------------            
   public String getY1( )
   {
   	return y1;
   }
   //-----------------------------------------            
   public void setX2( String passedX2 )
   {
         x2 = passedX2;
   }      
   //-----------------------------------------            
   public String getX2( )
   {
      return x2;
   }
   //-----------------------------------------            
   public void setY2( String passedY2 )
   {
  		y2 = passedY2;
   }      
   //-----------------------------------------            
   public String getY2( )
   {
  		return y2;
   }  
   //-----------------------------------------  
   public void setDistanceBetweenPoints( )
   {
   	calculateDistance( );
   } 
   //-----------------------------------------		    
   public double getDistanceBetweenPoints( )
   {
		if( ( x1 != null ) && ( y1 != null ) && ( x2 != null ) && ( y2 != null ) )
		{
			try
			{
				calculateDistance( );   
       	}
			catch(NumberFormatException nfe)
			{
				status = 1;
			}
  		}
     	return distanceBetweenPoints;
   }   	   
   //-----------------------------------------    
   public int getStatus( )
   {
   	return status;
   } 
   //-----------------------------------------                
   private void calculateDistance( )
   {			
		distanceBetweenPoints = Math.sqrt( ( Double.parseDouble( x1 ) - Double.parseDouble( x2 ) ) * 
                                         ( Double.parseDouble( x1 ) - Double.parseDouble( x2 ) ) + 
                                         ( Double.parseDouble( y1 ) - Double.parseDouble( y2 ) ) * 
                                         ( Double.parseDouble( y1 ) - Double.parseDouble( y2 ) ) );		
	}
   //-----------------------------------------
}
 
//=======================
//=======================
 
<%-- distanceCalculator2.jsp --%>
 
<jsp:useBean id="distance2" scope="page" class="calc.DistanceCalc2" />
<jsp:setProperty name="distance2" property="*" />
 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
 
<html>
      <head><title>JSP Distance Calculator using EL Statements, JSTL, and a JavaBean</title> </head>
      <body>
	<br/>
      	<font face="Verdana"><center><i>
            	<h2>JSP Distance Calculator using EL Statements, JSTL, and a JavaBean</h2>
            	</i></center></font>
 
	<c:set var="x1" value="${distance2.x1}"/>
	<c:set var="y1" value="${distance2.y1}"/>
	<c:set var="x2" value="${distance2.x2}"/>
	<c:set var="y2" value="${distance2.y2}"/>
	<c:set var="distanceBetweenPoints" value="${distance2.distanceBetweenPoints}"/>
	<c:set var="status" value="${distance2.status}"/>
 
 
            	<form method="post" action="distanceCalculator2.jsp">
                  	<br>
                  	<font size="2" face="Verdana">
                  	Please enter the value of X1:
                  	<font color="blue">*</font>
                  	<input type="text" name="x1" length="7"/>            
              	    	<br>
                  	</font>
 
                  	<font size="2" face="Verdana">
                  	Please enter the value of Y1:
                  	<font color="blue">*</font>
                  	<input type="text" name="y1" length="7"/>            
                  	<br>
                  	</font>
 
                  	<font size="2" face="Verdana">
                  	Please enter the value of X2:
                  	<font color="blue">*</font>
                  	<input type="text" name="x2" length="7"/>            
                  	<br>
                  	</font>
 
                  	<font size="2" face="Verdana">
                  	Please enter the value of Y2.
                  	<font color="blue">*</font>
                  	<input type="text" name="y2" length="7"/>            
                  	</font>
 
                  	<p>
                  	<input type="submit" value="Calculate"/>
                  	</p>
            	</form>
 
	<c:if test="${pageContext.request.method=='POST'}">
            	<c:choose>
 
		<c:when test="${status == 1}">
			<hr/><br/>
                        		<font size="4" face="Verdana" color="red">
                        		Please input numbers only.
			</font>
                  	</c:when> 
 
                  	<c:when test='${x1 == null}'>
                        		<hr/><br/>
			<font size="4" face="Verdana" color="red">
                        		You did not enter a value for X1.
			</font>
                  	</c:when>
 
                  	<c:when test='${y1 == null}'>
                        		<hr/><br/>
			<font size="4" face="Verdana" color="red">
                        		You did not enter a value for Y1.
			</font>
                  	</c:when>
 
                  	<c:when test='${x2 == null}'>
                        		<hr/><br/>
			<font size="4" face="Verdana" color="red">
                        		You did not enter a value for X2.
			</font>
                  	</c:when>
 
                  	<c:when test='${y2 == null}'>
                        		<hr/><br/>
			<font size="4" face="Verdana" color="red">
                        		You did not enter a value for Y2.
			</font>
                  	</c:when>
 
		<c:otherwise>
                                   	<hr/>
                        		<font face="Verdana"> <u>
                        		<h3>Output</h3>
                        		</u></font>
 
                        		<font size="4" face="Verdana" color="blue">
                        		X1 = ${x1} <br/>
                        		Y1 = ${y1} <br/>
                        		X2 = ${x2} <br/>
                        		Y2 = ${y2} <br/>
                        		</font>
 
                        		<br/>
                        		<font size="4" face="Verdana" color="blue"> 
                        		The distance between (X1, Y1) and (X2, Y2) is 
                        		<fmt:formatNumber value="${distanceBetweenPoints}" 
                                    	type="number" maxFractionDigits="15"/> 
			</font>
 
                  	</c:otherwise>
            	</c:choose>
	</c:if>
	
	<%--
	<font size="4" face="Verdana" color="green">
	<br/><br/>
        	x1=${x1} 
	<br/>
	y1=${y1} 
	<br/>
	x2=${x2} 
	<br/>
	y2=${y2}
	<br/>
        	distanceBetweenPoints=${distanceBetweenPoints}
	<br/>
	</font>
	--%>
 
      </body>
</html>

Open in new window

Thanks again for the superior assistance!