java - delete data from db with spaces in jsp -
this question has answer here:
unable delete data, db(mysql), spaces example:
"blabla blabla" or " blabla", data without spaces deleting: "blablabla"
here how value in jsp:
<a href=deletedata?id=<%= rs.getstring(1)></a>
and deletedata - servlet
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 java.io.ioexception; import java.sql.connection; import java.sql.drivermanager; import java.sql.statement; @webservlet("/deletedata") public class deletedata extends httpservlet { protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string value = request.getparameter("id"); try { class.forname("com.mysql.jdbc.driver"); connection conn = drivermanager.getconnection("jdbc:mysql://localhost:3306/evernotedb", "evernotedb", "0633739768z"); statement st = conn.createstatement(); st.executeupdate("delete note notename='" + value + "'"); response.sendredirect("/usernotes.jsp"); conn.close(); } catch (exception e) { e.printstacktrace(); } }
} think problem in - getstring function, on oracle website mentioned function getting rows, disappointed
you redirecting in href , spaces in url translated %20 that's why when pass "blabla blabla" delete not matching results. should sanitize value.
uggly fast way:
replace %20 empty string
right way:java: how unescape html character entities in java?
Comments
Post a Comment