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)
Code :
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.
Re: Why my update.jsp is not working?
This is a Java forum. You are using Javascript... Differences between Java and Javascript
Re: Why my update.jsp is not working?
Quote:
Originally Posted by
Tjstretch
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 ?
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
Re: Why my update.jsp is not working?
Quote:
Originally Posted by
copeg
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.