I'm trying to run a web application via tomcat 8.5 and keep getting this error after I run it. I'm able to get to the static home page but navigating from there gives me this error. Heres the file structure.
This is the code for my servlet currently:
package controllers;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import concrete.ConcreteProject;
/**
* Servlet implementation class ConcreteProjectServlet
*/
@WebServlet(
description = "A controller for the Concrete Project application",
urlPatterns = {
"/ConcreteProjectServlet",
"/getSlabHTML",
"/cost.jsp"
})
public class ConcreteProjectServlet extends HttpServlet {
private static final long serialVersionUID = 3649273685L;
/**
* @see HttpServlet#HttpServlet()
*/
public ConcreteProjectServlet() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// get the input data from the request object
double slabWidth = Double.parseDouble(request.getParameter("slabWidth"));
double slabLength = Double.parseDouble(request.getParameter("slabLength"));
double slabThickness = Double.parseDouble(request.getParameter("slabThickness"));
double bagWeight = Double.parseDouble(request.getParameter("bagWeight"));
//perform any conversions on the data to make it usable in our code
//create a project object with the input data (this is one of the outputs)
ConcreteProject cp = new ConcreteProject(slabWidth, slabLength, slabThickness, bagWeight);
//using the project object, create the output as a string
String projectHTML = cp.getSlabHTML();
//store the output value somewhere that the view can get it - the request object will work here
request.setAttribute("projectHTML",projectHTML);
request.setAttribute("cp", cp);
//pass control to the jsp view component
String url = "/cost.jsp";
RequestDispatcher dispatcher = request.getRequestDispatcher(url);
dispatcher.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
And for the JSP file:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Concrete Project Calculator</title>
</head>
<body>
<h1>Concrete Project Calculator</h1>
<p>Here are the results of the project calculations:</p>
SLAB DIMENSIONS HERE <br>
NUMBER OF BAGS HERE <br>
TOTAL COST HERE <br>
<p>
<a href="index.html"> Calculate Again </a>
</p>
</body>
</html>
My index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Concrete Project Calculator</title>
</head>
<body>
<h1>Concrete Project Calculator</h1>
<h3>Please enter the following values:</h3>
<form action="getSlabHTML" method="get">
<p>
<label for="slabWidth">
Slab Width (in feet):
</label>
<input type="number" name="slabWidth" value="" min="0"/>
</p>
<p>
<label for="slabLength">
Slab Length (in feet):
</label>
<input type="number" name="slabLength" value="" min="0"/>
</p>
<p>
<label for="slabThickness">
Slab Thickness (in inches):
</label>
<input type="number" name="slabThickness" value="" min="0"/>
</p>
<p>
<label>
Choose a Bag Weight:<br>
</label>
<input type="radio" id="80" name="bagWeight" value="80 lbs"/>
<label for="80"> 80 lbs </label><br>
<input type="radio" id="60" name="bagWeight" value="60 lbs"/>
<label for="60"> 60 lbs </label><br>
<input type="radio" id="50" name="bagWeight" value="50 lbs"/>
<label for="50"> 50 lbs </label>
</p>
<p>
<input type="submit" name="submit" value="Calculate" />
<input type="reset" name="reset" value="Reset" />
</p>
</form>
</body>
</html>
And the ConcreteProject.java code:
**
*
*/
package concrete;
import java.text.NumberFormat;
/**
* @author jordanwebster
*
*/
public class ConcreteProject {
private double slabWidth; //width of slab in feet
private double slabLength; //length of slab in feet
private double slabThickness; //thickness of slab in inches
private double bagWeight; //weight of bag chosen in lbs
/**
*
*/
public ConcreteProject() {
}
/**
* @param slabWidth
* @param slabLength
* @param slabThickness
* @param bagWeight
*/
public ConcreteProject(double slabWidth, double slabLength, double slabThickness, double bagWeight) {
this.slabWidth = slabWidth;
this.slabLength = slabLength;
this.slabThickness = slabThickness;
this.bagWeight = bagWeight;
}
/**
* @return the slabWidth
*/
public double getSlabWidth() {
return slabWidth;
}
/**
* @param slabWidth the slabWidth to set
*/
public void setSlabWidth(double slabWidth) {
this.slabWidth = slabWidth;
}
/**
* @return the slabLength
*/
public double getSlabLength() {
return slabLength;
}
/**
* @param slabLength the slabLength to set
*/
public void setSlabLength(double slabLength) {
this.slabLength = slabLength;
}
/**
* @return the slabThickness
*/
public double getSlabThickness() {
return slabThickness;
}
/**
* @param slabThickness the slabThickness to set
*/
public void setSlabThickness(double slabThickness) {
this.slabThickness = slabThickness;
}
/**
* @return slab volume based on width, length, thickness
*/
public double getSlabVolume() {
double slabVolume;
slabVolume = (this.slabWidth/3) * (this.slabLength/3) * (this.slabThickness/36);
return slabVolume;
}
/**
* @return the bagWeight
*/
public double getBagWeight() {
return bagWeight;
}
/**
* @param bagWeight the bagWeight to set
*/
public void setBagWeight(int bagWeight) {
this.bagWeight = bagWeight;
}
/**
* @return calculate bag volume by bag weight
*/
public double getBagVolume() {
double bagVolume;
if (this.bagWeight == 80) {
bagVolume = 0.022;
}
else if (this.bagWeight == 60) {
bagVolume = 0.0167;
}
else if (this.bagWeight == 50) {
bagVolume = 0.0138;
}
else {
bagVolume = 0;
}
return bagVolume;
}
/**
* @param numBags the numBags to set
*/
public double getNumBags() {
double numBags;
numBags = this.getSlabVolume()/this.getBagVolume();
return numBags;
}
public double getTotalCost() {
double totalCost;
double costPerBag;
if (this.bagWeight == 80) {
costPerBag = 3.75;
}
else if (this.bagWeight == 60) {
costPerBag = 2.83;
}
else if (this.bagWeight == 50) {
costPerBag = 2.45;
}
else {
costPerBag = 0;
}
totalCost = costPerBag * this.getNumBags();
return totalCost;
}
public String getSlabHTML() {
String slabHTML = "";
NumberFormat cf = NumberFormat.getCurrencyInstance();
NumberFormat vf = NumberFormat.getInstance();
cf.setMaximumFractionDigits(2); //rounds dollar amount to 2 decimal places
vf.setMaximumFractionDigits(4); //rounds volume to 4 decimal places
slabHTML += "<h2>Concrete Calculations </h2>";
slabHTML += "<p> Slab Width: " + vf.format(slabWidth) + " feet </p>";
slabHTML += "<p> Slab Length: " + vf.format(slabLength) + " feet </p>";
slabHTML += "<p> Slab Thickness: " + vf.format(slabThickness) + " inches </p>";
slabHTML += "<p> Slab Volume: " + vf.format(this.getSlabVolume()) + " cubic yards </p>";
slabHTML += "<p> Number of Bags Needed: " + vf.format(this.getNumBags()) + " </p>";
slabHTML += "<p> Total cost of project using " + this.getBagWeight() + "lb bags: " + cf.format(this.getTotalCost()) + " </p>";
return slabHTML;
}
}
Any help would be appreciated!