Error: Requested resource not available for Servlet

Reply

Join Date: Apr 2009
Posts: 31
Reputation: suretd is an unknown quantity at this point 
Solved Threads: 0
suretd suretd is offline Offline
Light Poster

Error: Requested resource not available for Servlet

 
0
  #1
Jun 30th, 2009
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?

  1. /*
  2. Chapter 12: Question 4: Creating HTML Forms in JAVA (ASS: 78983D-G)
  3. Programmer: Suret Delport (Student No. 10007349767)
  4. Date: 20 June 2009
  5. Filename: HTMLBank.java
  6. Purpose: Servlet that uses HTML to get input from user, determines balance and then adds or
  7. subtracts from the balance and lastly calculates the total balance again.
  8. */
  9.  
  10. import javax.servlet.*;
  11. import javax.servlet.http.*;
  12.  
  13. import java.io.*;
  14. import java.util.*;
  15. import java.net.*;
  16. import java.text.DecimalFormat;
  17.  
  18. public class HTMLBank extends HttpServlet
  19. {
  20. private Account act;
  21. public DecimalFormat pattern = new DecimalFormat("$#,000.00");// To set a pattern for display
  22. public double actBalance = 10000.00; // initial display value
  23. public String displayBalance = pattern.format(actBalance);
  24. double entered = 0.0;
  25.  
  26. public void init(ServletConfig conf)throws ServletException
  27. {
  28. super.init(conf);
  29. act = new Account();
  30.  
  31. }
  32. public void doGet(HttpServletRequest req, HttpServletResponse res)
  33. throws ServletException, IOException
  34. {
  35. res.setContentType("text/html");
  36. PrintWriter out = res.getWriter();
  37.  
  38. res.setHeader("Expires","Tues, 01 Jan 1980 00:00:00 GMT");
  39.  
  40. HttpSession session = req.getSession(true); // get current session
  41. if(entered >= 0.0)
  42. {
  43. out.println("<html>");
  44. out.println("<head>");
  45. out.println("<title>Online Bank Simulator</title>");
  46. out.println("</head>");
  47. out.println("<body>");
  48. out.println("<form method=POST action=/servlet/HTMLBank>");
  49. out.println("<center>");
  50. out.println("<hr>");
  51. out.println("<h1>Banking Simulation</h1><br>");
  52. out.println("Amount: <input type=text name=ENTRY size=20 maxlength=15><br><br>");
  53. out.println("Balance:"+displayBalance+"<br><br>");
  54. out.println("<input type=submit name=DEPOSIT value=\"Deposit\"> ");
  55. out.println("<input type=submit name=WITHDRAW value=\"Withdraw\"> ");
  56. out.println("<input type=submit name=BALANCE value=\"Balance\"> <br><br>");
  57. out.println("<hr>");
  58. out.println("</form>");
  59. out.println("</table>");
  60. out.println("</body>");
  61. out.println("</html>");
  62. }
  63. else
  64. {
  65. out.println("<HTML>");
  66. out.println("<HEAD>");
  67. out.println("<TITLE>Incorrect Input Warning..</TITLE>");
  68. out.println("</HEAD>");
  69. out.println("<BODY>");
  70. out.println("<H2>YOU HAVE ENTERED AN INCORRECT AMMOUNT!!!</H2>");
  71. out.println("<H3>You must enter a number only and it must be greater than 0.0</H3>");
  72. out.println("</from>");
  73. out.println("</BODY>");
  74. out.println("</HTML>");
  75. }
  76. }
  77. public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
  78. {
  79. try
  80. {
  81. entered = Double.parseDouble(req.getParameter("ENTRY"));
  82. }
  83. catch(NumberFormatException e)
  84. {
  85. entered = 0.0;
  86. }
  87.  
  88. synchronized(act)
  89. {
  90. if((req.getParameter("WITHDRAW")!=null) && (entered < actBalance))
  91. {
  92. actBalance = actBalance - entered;
  93. entered = 0.0; // reset value so that accidental presses on button dont affect total
  94. }
  95. if((req.getParameter("DEPOSIT")!=null) && (entered > 0))
  96. {
  97. actBalance = actBalance + entered;
  98. entered = 0.0; // reset value so that accidental presses on button dont affect total
  99. }
  100. if(req.getParameter("BALANCE")!=null)
  101. {
  102. displayBalance = pattern.format(actBalance);
  103. }
  104. }
  105. doGet(req, res);
  106. }
  107. class Account
  108. {
  109. public int balance;
  110. }
  111. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,629
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Error: Requested resource not available for Servlet

 
0
  #2
Jun 30th, 2009
> 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?
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC