Hi All,

I have created a servlet HTMLBank.java which I need to display in my browser. I am using Tomcat as my server. I have saved the class for HTMLBank in:
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\Classes\servlet

But when i try to "run" my servlet in my browser, i get a message that HTMLBank cannot be located. I am not sure what I am doing wrong. Am I saving my file in the correct default location?

Can anyone please advise? I am not sure if you will need to check my code ... that is is compiling perfectly now.

But here it is ... in case you might need to see it:

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.util.*;
import java.net.*;
import java.text.DecimalFormat;

public class HTMLBank extends HttpServlet
{
	private Account act;
	public DecimalFormat pattern = new DecimalFormat("$#,000.00");// To set a pattern for display
	public double actBalance = 10000.00;                          // initial display value
	public String displayBalance = pattern.format(actBalance);
	double entered = 0.0;

	public void init(ServletConfig conf)throws ServletException
	{
		super.init(conf);
		act = new Account();

	}
	public void  doGet(HttpServletRequest req, HttpServletResponse res)
                      throws ServletException, IOException
    {
	    res.setContentType("text/html");
	    PrintWriter out = res.getWriter();

	    res.setHeader("Expires","Tues, 01 Jan 1980 00:00:00 GMT");

	    HttpSession session = req.getSession(true); // get current session
		if(entered >= 0.0)
	    {
			out.println("<html>");
			out.println("<head>");
			out.println("<title>Online Bank Simulator</title>");
			out.println("</head>");
			out.println("<body>");
			out.println("<form method=POST action=/servlet/HTMLBank>");
			out.println("<center>");
			out.println("<hr>");
			out.println("<h1>Banking Simulation</h1><br>");
			out.println("Amount: <input type=text name=ENTRY size=20 maxlength=15><br><br>");
			out.println("Balance:"+displayBalance+"<br><br>");
			out.println("<input type=submit name=DEPOSIT value=\"Deposit\">        ");
			out.println("<input type=submit name=WITHDRAW value=\"Withdraw\">        ");
			out.println("<input type=submit name=BALANCE value=\"Balance\">        <br><br>");
			out.println("<hr>");
			out.println("</form>");
			out.println("</table>");
			out.println("</body>");
			out.println("</html>");
		}
		else
		{
			out.println("<HTML>");
			out.println("<HEAD>");
			out.println("<TITLE>Incorrect Input Warning..</TITLE>");
			out.println("</HEAD>");
			out.println("<BODY>");
			out.println("<H2>YOU HAVE ENTERED AN INCORRECT AMMOUNT!!!</H2>");
			out.println("<H3>You must enter a number only and it must be greater than 0.0</H3>");
			out.println("</from>");
			out.println("</BODY>");
			out.println("</HTML>");
		}
	}
	public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
	{
		try
		{
			entered = Double.parseDouble(req.getParameter("ENTRY"));
		}
		catch(NumberFormatException e)
		{
			entered = 0.0;
		}

		synchronized(act)
		{
			if((req.getParameter("WITHDRAW")!=null) && (entered < actBalance))
			{
				actBalance = actBalance - entered;
				entered = 0.0;			// reset value so that accidental presses on button dont affect total
			}
			if((req.getParameter("DEPOSIT")!=null) && (entered > 0))
			{
				actBalance = actBalance + entered;
				entered = 0.0;			// reset value so that accidental presses on button dont affect total
			}
			if(req.getParameter("BALANCE")!=null)
			{
				displayBalance = pattern.format(actBalance);
			}
		}
		doGet(req, res);
	}
	class Account
	{
		public int balance;
	}
}

Thank you for your help

Hi Peter,

I am finishing up my JAVA programming diploma through a college here and the text book they are using is strarting to seem to me VERY old ... I REALLY struggle with the tutorials they provide ... which is why I am posting so much on Daniweb and asking for so much assistance. I cannot wait to get the diploma done and start to learn about "modern JAVA"
Thanks for the advise. I have saved your link as a new favorite and will read through it.

This article has been dead for over six months. Start a new discussion instead.