i have jsp form which sends values to the mysql database and a servlet then displays all the values from the database. how do i go about comibining the into one form? any tutorial or advice will be welcomed
Printable View
i have jsp form which sends values to the mysql database and a servlet then displays all the values from the database. how do i go about comibining the into one form? any tutorial or advice will be welcomed
Code:[U]SaveToDB.jsp[/U]
<form method='post' action='SaveToDB.jsp'>
<input type='text' name='name'/>
<input type='submit' name='Submit' value='Send'/>
</form>
<%
String name = request.getParameter("name");
if(name!=null) { enterIntoDB(name); }
%>
<%= valueFromDB() %>
<%!
static public String valueFromDB() {
String values = {code for retreiving name from DB }
return values;
}
static public String enterIntoDB(String name) {
{code for entering name into DB }
return values;
}
%>
so i see the form method sends it to same .jsp page and the request.getParam picks it back up and
sends to db if not null, then calls the method to retrieve it...thanks, i'll try this out
what keycode says is generally the behavior you want: if form is submitted, do one task. if form isn't submitted, do another task.
however, i think that it's better practice to have jsp's only outputting information. forms should post to servlets (not jsp's), which should process information and forward to the jsp for whatever the user sees. just my opinion though