| | |
Error: Requested resource not available for Servlet
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2009
Posts: 31
Reputation:
Solved Threads: 0
Good Day,
When I run my servlet in my web browser, everything runs fine ... until i press one of the option buttons, Deposit, Withdraw or Balance, then i get the following error:
type Status report
message /servlet/HTMLBank
description The requested resource (/servlet/HTMLBank) is not available.
Here is the code as well. What am I missing? Why are my buttons not working?
When I run my servlet in my web browser, everything runs fine ... until i press one of the option buttons, Deposit, Withdraw or Balance, then i get the following error:
type Status report
message /servlet/HTMLBank
description The requested resource (/servlet/HTMLBank) is not available.
Here is the code as well. What am I missing? Why are my buttons not working?
JSP Syntax (Toggle Plain Text)
/* Chapter 12: Question 4: Creating HTML Forms in JAVA (ASS: 78983D-G) Programmer: Suret Delport (Student No. 10007349767) Date: 20 June 2009 Filename: HTMLBank.java Purpose: Servlet that uses HTML to get input from user, determines balance and then adds or subtracts from the balance and lastly calculates the total balance again. */ 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; } }
> When I run my servlet in my web browser, everything runs fine ...
> until i press one of the option buttons, Deposit, Withdraw or
> Balance, then i get the following error:
This is because HTML doesn't know anything about your servlet project. Is the name of your project "servlet"? If no, then you need to specify the name of your Servlet project since you are specifying the absolute URL in the `action' attribute of your FORM.
BTW, the reason for the error is pretty simple; there is no resource mapped to the URL "/servlet/HTMLBank". How do you originally access the servlet which is working? How is your web.xml configured?
> until i press one of the option buttons, Deposit, Withdraw or
> Balance, then i get the following error:
This is because HTML doesn't know anything about your servlet project. Is the name of your project "servlet"? If no, then you need to specify the name of your Servlet project since you are specifying the absolute URL in the `action' attribute of your FORM.
BTW, the reason for the error is pretty simple; there is no resource mapped to the URL "/servlet/HTMLBank". How do you originally access the servlet which is working? How is your web.xml configured?
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed becau (ASP.NET)
- Error:The requested resources are not available (JSP)
- First Servlet (JSP)
- The requested resource is not available - Tomcat (JSP)
- JSP and Servlet using Tomcat (JSP)
- Servlet -: Error running from WAR file (JSP)
- about servlets at myeclipse. (JSP)
- An invalid character was found in text content. Error processing resource (Web Browsers)
- running servlets (JSP)
Other Threads in the JSP Forum
- Previous Thread: how can i add css in jsp website in dreamwiever 8
- Next Thread: I can't insert data into database
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






