Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Tolls

Thread: how to solve the problem of this error

  1. #1
    sally mally is offline Member
    Join Date
    Nov 2013
    Posts
    14
    Rep Power
    0

    Default how to solve the problem of this error

    HTTP Status 500 - For input string: "Chicken Rice Shop"

    --------------------------------------------------------------------------------

    type Exception report

    message For input string: "Chicken Rice Shop"

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    java.lang.NumberFormatException: For input string: "Chicken Rice Shop"
    java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
    java.lang.Integer.parseInt(Integer.java:492)
    java.lang.Integer.parseInt(Integer.java:527)
    stall.menu.MenuServlet.doPost(MenuServlet.java:51)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:647)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:51)


    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.


    --------------------------------------------------------------------------------

    Apache Tomcat/7.0.47

  2. #2
    sally mally is offline Member
    Join Date
    Nov 2013
    Posts
    14
    Rep Power
    0

    Default Re: how to solve the problem of this error

    my codes in menuServlet.java
    Java Code:
    package stall.menu;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    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 stall.stall.Stall;
    
    /**
     * Servlet implementation class MenuServlet
     */
    @WebServlet(
    		name = "MenuServlet",
    		urlPatterns = {"/jsp/menu/MenuServlet"})
    		
    public class MenuServlet extends HttpServlet {
    	private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public MenuServlet() {
            super();
            // TODO Auto-generated constructor stub
        }
    
    	/**
    	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
    		// TODO Auto-generated method stub
    		PrintWriter out = response.getWriter();
    		out.print("from doGet()");
    	}
    
    	/**
    	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    		PrintWriter out = response.getWriter();
    		
    		
    		// Get and parse menu data from jsp form
    		int stallId = Integer.parseInt(request.getParameter("Stall"));
    		String category = request.getParameter("category");
    		String name = request.getParameter("Name");
    		double price = Double.parseDouble(request.getParameter("price"));
    		
    		// Encapsulate in object
    		Stall stall = new Stall();
    		stall.setStallId(stallId);
    		
    		Menu menu = new Menu();
    		menu.setStall(stall);
    		menu.setCategory(category);
    		menu.setName(name);
    		menu.setPrice(price);
    		
    		// Add menu
    		try {
    			
    			MenuController menuCtrl = new MenuController();
    			int row = menuCtrl.addMenu(menu);
    			
    			if (row > 0)
    				out.print("Menu successfully inserted. Write a code to redirect to another page");
    		
    			
    		} catch (Exception e) {
    			out.println(e.getMessage());
    			e.printStackTrace();
    		
            } 
          
          //update menu
          MenuController menuCtrl = new MenuController();
          try {
    		  int result = menuCtrl.updateMenu(menu);
    		  out.print(result + "indicates number of record successfully updated. "
    		  + "Redirect to another page for user friendliness");
          
      	   } catch (Exception e) {
       				// TODO Auto-generated catch block
       				out.print(e.getMessage());
      	 }
    		
    		
    		
    	} 
    
    }
    Last edited by Tolls; 11-29-2013 at 11:03 AM.

  3. #3
    sally mally is offline Member
    Join Date
    Nov 2013
    Posts
    14
    Rep Power
    0

    Default Re: how to solve the problem of this error

    my codes in update.jsp

    Java Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <%@ page import="java.util.Vector" %>
    
    <%@ page import="stall.stall.Stall" %>
    <%@ page import="stall.menu.Menu" %>
      
    <%@ page import="stall.menu.MenuController" %> 
    
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Update Menu</title>
    <style type="text/css">
    <!--
    body {
    	font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
    	background-color: #42413C;
    	margin: 0;
    	padding: 0;
    	color: #000;
    }
    
    /* ~~ Element/tag selectors ~~ */
    ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
    	padding: 0;
    	margin: 0;
    }
    h1, h2, h3, h4, h5, h6, p {
    	margin-top: 0;	 /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
    	padding-right: 15px;
    	padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
    }
    a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
    	border: none;
    }
    
    /* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
    a:link {
    	color: #42413C;
    	text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
    }
    a:visited {
    	color: #6E6C64;
    	text-decoration: underline;
    }
    a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
    	text-decoration: none;
    }
    
    /* ~~ This fixed width container surrounds all other divs ~~ */
    .container {
    	width: 700px;
    	background-color: #FFFFFF;
    	margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
    }
    
    /* ~~ The header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo. ~~ */
    .header {
    	text-align:center;
    }
    
    /* ~~ These are the columns for the layout. ~~ 
    
    1) Padding is only placed on the top and/or bottom of the divs. The elements within these divs have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.
    
    2) No margin has been given to the columns since they are all floated. If you must add margin, avoid placing it on the side you're floating toward (for example: a right margin on a div set to float right). Many times, padding can be used instead. For divs where this rule must be broken, you should add a "display:inline" declaration to the div's rule to tame a bug where some versions of Internet Explorer double the margin.
    
    3) Since classes can be used multiple times in a document (and an element can also have multiple classes applied), the columns have been assigned class names instead of IDs. For example, two sidebar divs could be stacked if necessary. These can very easily be changed to IDs if that's your preference, as long as you'll only be using them once per document.
    
    4) If you prefer your nav on the right instead of the left, simply float these columns the opposite direction (all right instead of all left) and they'll render in reverse order. There's no need to move the divs around in the HTML source.
    
    */
    .sidebar1 {
    	float: left;
    	width: 180px;
    	background-color: #EADCAE;
    	padding-bottom: 10px;
    	
    }
    .content {
    	padding: 10px 0;
    	width: 100%;
    	float: left;
    	background-color: #0CF;
    	text-align:center;
    }
    .sidebar2 {
    	float: left;
    	width: 180px;
    	background-color: #EADCAE;
    	padding: 10px 0;
    }
    
    /* ~~ This grouped selector gives the lists in the .content area space ~~ */
    .content ul, .content ol { 
    	padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */
    }
    
    ul#navigation {list-style:none;position:relative; z-index:2;top:1px;display:table;border-left:1px solid #f5ab36;}
    ul#navigation li {float:left;}
    ul#navigation li a {background:#FFFFFF;color:#222;display:block;padding:6px 15px;text-decoration:none;border-right:1px solid #f5ab36;border-top:1px solid #f5ab36;border-right:1px solid #f5ab36;margin:0;}
    ul#navigation li a.selected {border-bottom:1px solid #fff;color:#344385;background:#fff;}
    /* ~~ The footer styles ~~ */
    .footer {
    	padding: 10px 0;
    	background-color: #CCC49F;
    	position: relative;/* this gives IE6 hasLayout to properly clear */
    	clear: both; /* this clear property forces the .container to understand where the columns end and contain them */
    }
    
    /* ~~ Miscellaneous float/clear classes ~~ */
    .fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
    	float: right;
    	margin-left: 8px;
    }
    .fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
    	float: left;
    	margin-right: 8px;
    }
    .clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the .container) if the .footer is removed or taken out of the .container */
    	clear:both;
    	height:0;
    	font-size: 1px;
    	line-height: 0px;
    }
    -->
    </style>
    </head>
    
    <body>
    
    <div class="container">
    <p></p>
      <div class="header"><!-- end .header --></div>
      <ul id="navigation">
          <li><a href="#">STALL</a></li>
          <li><a href="#">STALL MENU</a></li>
          <li><a href="#">REPORT</a></li>
      </ul>
      <div class="content"><!-- end .content -->Update Menu</div>
      <h1></h1>
    
    
    <%
    	// Get and parse menu id
    	int id = Integer.parseInt(request.getParameter("menu"));
    
    	
    	Menu menuToUpdate = new Menu();
    	menuToUpdate.setMenuId(id);
    	
    	try {
    		MenuController menuCtrl = new MenuController();
    		menuToUpdate = menuCtrl.getMenu(menuToUpdate);
    	
    	} catch (Exception e) {
    		out.print(e.getMessage());
    	}
    %>  
    
    <h2><%= menuToUpdate.getMenuId() %> - <%= menuToUpdate.getName() %></h2>
    
      
      <form id="form1" name="form1" method="post" action="MenuServlet">
        	<input type="hidden" name="mode" value="update" />
        <table width="66%" align="center">
      <tr>
        <td width="45%">Name Of Stall</td>
        <td width="55%">
          <label for="stall"></label>   
          <input type="text" name="Stall" id="Stall" value="<%= menuToUpdate.getStall().getName() %>"/>
         </td>              
      </tr>
      
      <tr>
         <td width="45%">Category Of Menu</td>
        <td width="55%">
          <label for="category"></label>
          <%
    			String type = menuToUpdate.getCategory();
        		String category[] = {"Western", "Dessert", "Malay Cuisine", "Thai", "Sizzling"};  
        		  
    	  %>
          <select name="category" id="category">
    <%
    		for (int index = 0; index < category.length; index++) {
    %>
    			<option value="<%= category[index] %>"  
    <%
    			if (type.equalsIgnoreCase(category[index]))
    				out.print(" selected ");
    %>
    			><%= category[index] %></option>						
    <%			
    		}
    %>      		
          </select>
       </td>
      </tr>
      
      <tr>
        <td>Menu</td>
        <td>
          <label for="Menu"></label>
          <label>
            <input type="text" name="Menu" id="Menu" value="<%= menuToUpdate.getName() %>"/>
            </label></td>
      </tr>
    
      <tr>
    	 <td>Price</td>
       	 <td>
          <label for="Price"></label>
          <label>
            <input type="text" name="Price" id="Price" value="<%= menuToUpdate.getPrice() %>" />
            </label></td>
       </tr>
    
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td></td>
        <td><input type="submit" name="Cancel" id="Cancel" value="Reset" />
          <input type="submit" name="Update" id="Update" value="Submit" /></td>
      </tr>
        </table>
        <!-- end .content -->
    
        </form>
      <div class="footer">
      <p></p>
        <!-- end .footer --></div>
    </div>
    
     
    </body>
    </html>
    Last edited by Tolls; 11-29-2013 at 11:04 AM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default Re: how to solve the problem of this error

    Please don't hijack another thread, especially one that's 4 years old.
    I've closed that one.

    Your error is quite clear.
    You are trying to get parseInt to parse a string that is not an integer...in this case "Chicken Rice Shop".

    When posting code please wrap it in [code] tags [/code].
    I'll do it for you this time.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default Re: how to solve the problem of this error

    Looking at that code (do you think it was entirely necessary to post the JSP with all the CSS?):
    Java Code:
    <input type="text" name="Stall" id="Stall" value="<%= menuToUpdate.getStall().getName() %>"/>
    Java Code:
    int stallId = Integer.parseInt(request.getParameter("Stall"));
    "Stall" is clearly a name, not an id.
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 5
    Last Post: 05-09-2012, 06:18 PM
  2. How to solve ArrayIndexBoundOfException error
    By amityadav9314 in forum New To Java
    Replies: 22
    Last Post: 09-11-2010, 01:35 AM
  3. plz solve this error
    By silversurfer2in in forum AWT / Swing
    Replies: 14
    Last Post: 06-15-2010, 04:30 PM
  4. how to solve syntax error
    By pro85 in forum Java Applets
    Replies: 5
    Last Post: 04-06-2009, 12:20 PM
  5. Help mi solve my error
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-11-2008, 06:26 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •