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

Thread: please help me

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

    Default please help me

    how to solve this errors

    HTTP Status 500 - For input string: "The Kitchens"

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

    type Exception report

    message For input string: "The Kitchens"

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

    exception

    java.lang.NumberFormatException: For input string: "The Kitchens"
    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.

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

    Default Re: please help me

    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 stallName = 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(stallName);

    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());
    }



    }

    }

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

    Default Re: please help me

    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;paddi ng: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>

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

    Default Re: please help me

    MenuController.java

    java codes :





    package stall.menu;

    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.util.Vector;

    import stall.stall.Stall;

    import dbconnector.DbConnector;

    public class MenuController {

    DbConnector dbCon;
    Connection conn;

    public MenuController() {
    dbCon = new DbConnector();
    }


    public int updateMenu (Menu menu) throws Exception {

    //Establish database connection
    conn = dbCon.getConnection();

    //Form SQL
    String sql = "update Menu"
    + "set stall = ?, "
    + "set category = ?, "
    + "menu = ? ,"
    + "price = ? ,"
    + "where id = ?";



    // Create PreparedStatement object and set parameter
    PreparedStatement ps = conn.prepareStatement(sql);

    ps.setString(2, menu.getName());
    ps.setDouble(3, menu.getPrice());
    ps.setString(4, menu.getCategory());
    ps.setInt(5, menu.getStall().getStallId());


    // Execute SQL statement
    int row = ps.executeUpdate();

    //close connection
    conn.close();

    return row;
    }

    public int addMenu(Menu menu) throws Exception {

    // Establish database connection
    conn = dbCon.getConnection();

    // Form SQL
    String sql = "insert into Menu " +
    "(name, price, category, stall) " +
    "values (?,?,?,?)";

    // Create PreparedStatement and set parameters
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setString(1, menu.getName());
    ps.setDouble(2, menu.getPrice());
    ps.setString(3, menu.getCategory());
    ps.setInt(4, menu.getStall().getStallId());

    // Execute SQL statement
    int row = ps.executeUpdate();

    conn.close();

    return row;


    }

    public Vector<Menu> getMenus (Stall stall) throws Exception {

    // Establish database connection
    conn = dbCon.getConnection();

    // Form SQL statement
    String sql = "select m.Id, m.Name, m.price, m.category " +
    "from Stall s, Menu m " +
    "where s.Id = m.stall " +
    "and s.name = ?";

    // Create PreparedStatement object and set parameter
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setString(1, stall.getName());

    // Execute sql statement and get result
    ResultSet rs = ps.executeQuery();

    // Wrap result in object
    Vector<Menu> menus = new Vector<Menu>();
    while (rs.next()) {

    Menu currentMenu = new Menu();
    currentMenu.setMenuId(rs.getInt(1));
    currentMenu.setName(rs.getString(2));
    currentMenu.setPrice(rs.getDouble(3));
    currentMenu.setCategory(rs.getString(4));

    // Add menu to vector
    menus.add(currentMenu);
    }

    // Close connection
    conn.close();

    return menus;
    }

    public Menu getMenu (Menu menu) throws Exception {

    // Establish database connection
    conn = dbCon.getConnection();

    // Form SQL statement
    String sql = "select m.*, s.name " +
    "from Stall s, Menu m " +
    "where m.Id = ? " +
    "and s.id = m.stall ";

    // Create PreparedStatement object and set parameter
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setInt(1, menu.getMenuId());

    // Execute sql statement and get result
    ResultSet rs = ps.executeQuery();

    // Wrap result in object
    Stall stall = new Stall();
    while (rs.next()) {

    menu.setName(rs.getString(2));
    menu.setPrice(rs.getDouble(3));
    menu.setCategory(rs.getString(4));

    stall.setName(rs.getString(6));
    menu.setStall(stall);


    }

    // Close connection
    conn.close();

    return menu;
    }

    }

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,729
    Rep Power
    5

    Default Re: please help me

    Try reading the replies you got the last time you asked this exact question:

    how to solve the problem of this error
    Tolls likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

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
  •