I am writing a simple JSP to calculate the distance between 2 points. When I click on the "Submit" button, I get the following HTTP 404 error:
HTTP Status 404 - /distanceCalc/distanceCalc
ulator.jsp
%20method=
--------------------------
----------
----------
----------
----------
----------
----
type Status report
message /distanceCalc/distanceCalc
ulator.jsp
%20method=
description The requested resource (/distanceCalc/distanceCal
culator.js
p%20method
=) is not available.
--------------------------
----------
----------
----------
----------
----------
----
Apache Tomcat/6.0.16
What am I missing here? Thank you in advance!
<%@ page import="java.lang.Math.*" %>
<html>
<head><title>JSP Distance Calculator</title><head>
<body>
<h1>Distance Calculator</h1>
<%
String x1 = request.getParameter( "x1" );
String y1 = request.getParameter( "y1" );
String x2 = request.getParameter( "x2" );
String y2 = request.getParameter( "y2" );
if( ( x1 != null ) && ( y1 != null ) &&
( x2 != null ) && ( y2 != null ) )
{
try
{
Double.valueOf( x1 ).doubleValue( );
Double.valueOf( y1 ).doubleValue( );
Double.valueOf( x2 ).doubleValue( );
Double.valueOf( y2 ).doubleValue( );
%>
<h2>Output</h2>
<font size="3" face="Verdana">
<p>X1 is <%= x1 %></p>
<p>Y1 is <%= y1 %></p>
<p>X2 is <%= x2 %></p>
<p>Y2 is <%= y2 %></p>
<p>The distance between (X1, Y1) and (X2, Y2) is
<%= 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 ) ) ) %>
</p>
</font>
<hr />
<%
}
catch( Exception e )
{
%>
<h2>Error</h2>
<font size="3" face="Verdana" color="red">
<p>Please complete all fields</p>
</font>
<hr />
<%
}
}
%>
<form action="distanceCalculator.jsp method="post">
<p>Please enter the value of X1:
<input type="text" name="x1" length="7"/>
</p>
<p>Please enter the value of Y1:
<input type="text" name="y1" length="7"/>
</p>
<p>Please enter the value of X2:
<input type="text" name="x2" length="7"/>
</p>
<p>Please enter the value of Y2:
<input type="text" name="y2" length="7"/>
</p>
<p>
<input type="submit" value="Submit"/>
</p>
</form>
</body>
</html>
Open in new window
<form action="distanceCalculator