Issue
I have a html form in jsp page which on submit is going to servlet ..After executing the functions in servlet i am again redirecting it to the same jsp page from which it has been invoked with a success message to display now on the same jsp page but i don't know how to do this ...
Here is my jsp form code..
<form action="CallTimer" method="GET">
<label class="button2">Set Date: </label>
<input type="text" name="date" id="date">
<label class="button2">Set Hour </label>
<input type="text" name="hour" id="hour">
<label class="button2">Set Minute: </label>
<input type="text" name="minute" id="minute">
<input type="Submit" name="Submit" value="Submit" id="Submit">
<br/><br/>
<label class="button2">Set File-Path: </label>
<input type="text" name="filepath" id="filepath">
</form>
And here is my servlet redirect code.
response.sendRedirect("Automail.jsp");
Solution
As per your requirement I would suggest you to go for ajax.I gave a simple example how to pass data to servlet.Click here to know more about jquery ajax
$.ajax(
{
type: "get",
url: "CallTimer", //Your full URL goes here
data: { name: name1, date: date1,hour:hour1,filepath:filepath1,minute:minute1},
success: function(data, textStatus, jqXHR){
alert("success");
},
error: function(jqXHR){
alert(jqXHR.responseStatus);
}
});
note name-parameter name and name1 parameter value,hour parameter name and hour1 parameter value.Similarily for others.Dont use get action in forms because parameter values will be displayed in the url and also there is a limit of 2048 characters
Answered By - user2948112