Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Why my update.jsp is not working?

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why my update.jsp is not working?

    I have a update.jsp in which a member after viewing a display page is allowed to click on the row and then update that particular row. Then a update page will called the data from the database and displayed the data that was entered earlier and allowed the user to make changes and update from there by overwriting the old data.

    But, when I use the option for the location and highlighted the desired location choosing from a list of options, and updated, it doesn't update the new location and the old location remains.

    I hope someone can advise me what's wrong with my code below:

    (Sorry I know some of you will say don't mix the logic with the JSP but now I have no choice because I have yet learnt how to separate the two)
     
     if (request.getParameter("action") != null) {
                    int selectionId = Integer.parseInt(request.getParameter("ID"));
     
    String Location = request.getParameter("txtLocations");
    <tr>
                        <td>Location</td>
                        <td><select name="txtLocations" id="txtLocations">
                                <option value="Adx">Adx
                                <option value="Alj">Alj
                                <option value="AMK">AMK
                                <option value="Bal">Bal
          </tr>       
     
    String sql = "UPDATE members SET strLocation = '" + Location +"' where id= " + selectionId;
     
    <html>
            Member Id = <%= request.getParameter("ID")%> Successfully Updated ! <br><br>
            <a href="DisplayData.jsp"> Return to Member Display</a>
        </html>
        <%} else {%>
        <%
     
    String strLocation = null;
     
     rs = stmt.executeQuery("SELECT * from members where members.ID = "
                    + selectionId + "");
            if (rs.next()) {
    strLocation = rs.getString("strLocation");
     } else {
    strLocation = "Unknown.";
     }
        %>
        <html>
     
    <form action="update.jsp" method ="post" name="update">
            </center>
            <input type="hidden" value="list" name="action">
            <input type="hidden" value=<%= request.getParameter("ID")%> name="ID">
     
    <td>Location</td>
                        <td><select name="txtLocations" id="txtLocations">
                                <option value="Adx">Adx
                                <option value="Alj">Alj
                                <option value="AMK">AMK
     
    <td align="right">
                        <input type="submit" id="btnSubmit" name="Update Member" value="Update Member<%= request.getParameter("ID")%>">
                    </td></tr>
            </table>
            <a href ="DisplayData.jsp">Return to Member Display Page</a>
            <a href ="logout.jsp">Log Out</a>
        </div>
     
        <%  stmt.close();
                    {
                        out.close();
     
                    }
                }%>
    </body>
    </html>

    Many thanks.


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Why my update.jsp is not working?

    This is a Java forum. You are using Javascript... Differences between Java and Javascript

  3. #3
    Member
    Join Date
    Jul 2011
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why my update.jsp is not working?

    Quote Originally Posted by Tjstretch View Post
    This is a Java forum. You are using Javascript... Differences between Java and Javascript
    FYI, the above code is copied from a business information system book and it says jsp.....

    Anyway, if you were me, how would you do the update for the above in real Java programming ?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Why my update.jsp is not working?

    Yes, this is jsp. However code such as this is difficult to provide guidance without more information. Do you want to load the information dynamically (eg without a page reload)? Then you will need to use ajax and javascript. I would recommend however, that you read up on how to properly write html - many of your elements lack closing tags which can throw everything for a loop

  5. #5
    Member
    Join Date
    Jul 2011
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why my update.jsp is not working?

    Quote Originally Posted by copeg View Post
    Yes, this is jsp. However code such as this is difficult to provide guidance without more information. Do you want to load the information dynamically (eg without a page reload)? Then you will need to use ajax and javascript. I would recommend however, that you read up on how to properly write html - many of your elements lack closing tags which can throw everything for a loop
    OK. I will try to correct the html portion. But, by closing the option list with </option> doesn't seem to help.

    And the most teething problem that it doesn't allow me to do the update at all.
    Basically, when a user highlight the option field, it is supposed to go into the database and when the display page is shown again, it will be reflected. My code doesn't.

    Hope you can give me some tips how to correct it. Many thanks.

Similar Threads

  1. [SOLVED] HELP ME! How to update quantity (JAVA)
    By kerrina in forum What's Wrong With My Code?
    Replies: 12
    Last Post: August 2nd, 2011, 03:27 AM
  2. button update when clicked
    By prettynew in forum AWT / Java Swing
    Replies: 4
    Last Post: March 13th, 2011, 04:47 PM
  3. Cannot update Jlabel in JApplet
    By rin in forum Java Applets
    Replies: 2
    Last Post: April 17th, 2010, 08:21 AM
  4. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM