Servlet Response Send Redirect

Servlet Response Send Redirect

Hi,

Thank you for your previous answer, the code works great. Sorry to bother you guys and perhaps this would be one of my last questions as I am almost finish with my web medical clinic app. Please if you guys can answer the following related to my last post regarding editing records.

1. In the code that you have given last time, I want to be able to do search on the Mysql table based on more than one column instead of one. what i mean is lets say user does a search on patient data based upon their id or last name. The result gets populated in the search table, user clicks a particular record but since this table has a patient who's visited many times, the id although FK is repeated and so the distinguishing element is the date of visit from the visit table. Can you please show me how I can pass more than one column value to the next jsp?

2. I have a servlet that saves patient data from a form into mysql table.I have some form validations through some javascript, but when the user clicks save or submit, there might be some Mysql errors that arise, I've catered to them by using JOptionPaneShowMessageDialogue in my servlet followed by a response.sendRedirect("index.jsp). the problem is that when a user has filled out a long form and gets a mysql error, I want instead of the response.sendRedirect is there some other method that the user doesn't loose the fields he already has filled because right now when I receive lets say a duplicate primary key(i have kept a non-auto increment), the user clicks ok on the message dialogue box and then index.jsp gets refreshed with all existing fields gone. Can you tell me a better way to do this?


Thank you So much,

Regards
View Answers

May 15, 2010 at 2:57 PM

Hi Friend,

Try the following code:

1)tablepopup.jsp:

<%@page import="java.sql.*"%>
<%
String id=request.getParameter("id");
String n=request.getParameter("name");
String address=request.getParameter("address");
String contact=request.getParameter("contactNo");
if((id!=null)&&(n!=null)&&(address!=null)&&(contact!=null)){
%>
<form action="edits.jsp">
<table border="1" >
<tr><td>Name:</td><td><input type="text" name="name" value="<%=n%>"></td></tr>
<tr><td>Address:</td><td><input type="text" name="address" value="<%=address%>"></td></tr>
<tr><td>Contact No:</td><td><input type="text" name="contactNo" value="<%=contact%>"></td></tr>
<tr><td></td><td><input type=submit name="edit" value="Edit"></td></tr>
</table>
<input type="hidden" name="id" value="<%=id%>">
</form>
<%
}
else{
%>
<form action="adds.jsp">
<table border="1">
<tr><td>Name:</td><td><input type="text" name="name" value=""></td></tr>
<tr><td>Address:</td><td><input type="text" name="address" value=""></td></tr>
<tr><td>Contact No:</td><td><input type="text" name="contactNo" value=""></td></tr>
<tr><td></td><td><input type=submit name="button" value="Add"></td></tr>
</table>
</form>
<%}
%>
<style>
.c1 {background-color: white;}
.c2 {background-color: white;}
.c3 {background-color: red;}
</style>
<script>
function ov(i){
document.getElementById(i).className="c3";
}
function ot(i,c){
document.getElementById(i).className=c;
}
function click(ide,d1,d2,d3){
var st=new String(d3);
if(st.length==1){
d3="0"+d3;
var d=d1+"-"+d2+"-"+d3;
window.location.replace('http://localhost:8080/examples/jsp/popup.jsp?id='+ide+'&&dd='+d,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes');
}
else{
var d=d1+"-"+d2+"-"+d3;
window.location.replace('http://localhost:8080/examples/jsp/popup.jsp?id='+ide+'&&dd='+d,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes');
}
}
</script>
</head>
<form>
Search:<input type="text" name="customer"><input type=submit value="Search">
</form>
<%
String name=request.getParameter("customer");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from client where name='"+name+"'");
%>
<table id="table" border="1">
<%
while(rs.next()){
String d=rs.getString("visitedDate");
String sub1=d.substring(0,4);
String sub2=d.substring(5,7);
String sub3=d.substring(8,10);

System.out.println(sub1+" "+sub2+" "+sub3);
%>
<tr id=<%=rs.getString("id")%> class=c1 onclick='click(<%=rs.getString("id")%>,<%=sub1%>,<%=sub2%>,<%=sub3%>)' onmouseover='ov("<%=rs.getString("id")%>")' onmouseout='ot("<%=rs.getString("id")%>","c1")'><td><%=rs.getString("name")%></td><td><%=rs.getString("address")%></td><td><%=rs.getString("contactNo")%></td><td><%=rs.getString("visitedDate")%></td></tr>
<%
}%>
</table>
</html>

May 15, 2010 at 3:03 PM

continue..

2)popup.jsp:

<%@page import="java.sql.*"%>
<%
String id=request.getParameter("id");
String dd=request.getParameter("dd");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
String query = "select * from client where id='"+id+"' and visitedDate='"+dd+"'";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);

String name="",add="",contact="",ide="";
while(rs.next()){
name=rs.getString("name");
add=rs.getString("address");
contact=rs.getString("contactNo");
ide=rs.getString("id");
}
response.sendRedirect("tablepopup.jsp?id="+ide+"&&name="+name+"&&contactNo="+contact+"&&address="+add);


%>

Please tell me whether index.jsp is the search page where we are displaying the search table.Also post the servlet code that saves the patient data.









Related Tutorials/Questions & Answers:
Servlet Response Send Redirect - JSP-Servlet
Servlet Response Send Redirect  Hi, Thank you for your previous... value to the next jsp? 2. I have a servlet that saves patient data from..., I've catered to them by using JOptionPaneShowMessageDialogue in my servlet
send redirect in JSP - JSP-Servlet
send redirect in JSP   How can I include a message i.e "redirected to this page because blah blah" in the send redirect page?  Hi friend, Please specify your problem the message print on the redirect to the next
Advertisements
Send Redirect in Servlet
Send Redirect in Servlet      ... servlet, then there we should use sendRedirect() method.  In send Redirect... or jsp. Then the servlet calls the sendRedirect() method of the response object
Send Redirect in Servlet
Send Redirect in Servlet     ... of our servlet, then there we should use sendRedirect() method.  In send... or not. If the password entered by the user is correct then the servlet will redirect
Send a Response Status in servlet
; This section illustrates you how to send response status in servlet. All...; Above example shows how a response has been send from the servlet... .style1 { font-weight: bold; } Send a Response
Redirect from servlet to servlet
Redirect from servlet to servlet  I want to insert data from Text box... to redirectServlet , and from this servlet I want to again forward my page to insertServlet(i.e...; <servlet-name>redirectServlet</servlet-name> <servlet
ModuleNotFoundError: No module named 'django-any-response-redirect-middleware'
ModuleNotFoundError: No module named 'django-any-response-redirect-middleware...: ModuleNotFoundError: No module named 'django-any-response-redirect-middleware' How...-response-redirect-middleware After the installation of django-any-response
redirect to multiple links from servlet
redirect to multiple links from servlet  hello , In my servlet page... the output in browser,i need to redirect to another link like the above line. i want redirect to multiple links simultaneously. anyone help me out
send email with attachments in servlet
send email with attachments in servlet  How can we send an email with attachments in servlet?   Send attached email in Java Servlet
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatcâ?¦ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatcâ?¦ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
send HTML Email with jsp and servlet
send HTML Email with jsp and servlet  Can You please show me how to send html Email using JSP and Servlet thank you
Sendredirect In Servlet
Sendredirect In Servlet In this section you will read about the sendredirect() method. sendredirect() method is used to redirect the control to the different... this method is used to redirect the control to different server or domain a new request
web page altering while displaying servlet response
web page altering while displaying servlet response  in my application one index.jsp and one servlet is there and the servlet contains some db code and i want to display response of that servlet in a div in my index.jsp
request header and response - JSP-Servlet
request header and response  hi sir, i have facing some problem in this qustion:- Create a servlet that accept a name and a phone number and contain 4 buttons add,update,delete and view .On clicking on the any of the button
Response Filter Servlet Example
Response Filter Servlet Example       This Example shows how to use of response filter in  Java Servlet. Filter reads own initial parameters and adds its value
SMS Send and Recieve - JSP-Servlet
SMS Send and Recieve  How can i embedded SMS service to send and receive SMS from mobile to my application
Java Servlet : Http Response Headers
Java Servlet : Http Response Headers In this tutorial, you will learn how to Http Response Headers works in java servlet. Http Response Headers : Web server sends response with one or more response headers including the document
How to send data by ajax to servlet? - Ajax
How to send data by ajax to servlet?  Hi, Can i send a value from a HTML file to servlet via Ajax? If it is possible please give me a sample code Thanks
How to send mail - JSP-Servlet
How to send mail  Thanks a lot ODBC is cleared to me now. Now,have another query about how we can send mail by using jsp. Actually i want to make a web page for a user feedback ,it must be send to our mail id
validating username and password in servlet and redirect to login page with error message if not valid
validating username and password in servlet and redirect to login page with error message if not valid  hi i want to validate my login page username and password in my servlet against database and if not valid want to display
how to send a mail - JSP-Servlet
how to send a mail  Dear sir, I am able to send a mail.But when a receiver gets a mail ,the matter will be shown in a single line . I am sending a following matter Dear Harini , U r bonus is 2000
Using redirect element & wild card
is generated by the new view using redirect response rather than rendering the response...Using redirect element & wild card          <redirect/>
calling servlet from JS and return response from servlet to JS
calling servlet from JS and return response from servlet to JS  hello...) which inturn calls a servlet(myServlet).servlet performs some DB related task.now i want this servlet(myServlet) to return a url(eg. pages/file.jsp
Send forgot Password through mail - JSP-Servlet
Send forgot Password through mail   hello every one I am... is provided) Now my question is how do i send the password if admin click on forgot password and i need to send that password through mail after answering a few
JSP:NEED RESPONSE ASAP PLEASE! - JSP-Servlet
JSP:NEED RESPONSE ASAP PLEASE!  Hi freind, If you could respond to my previous thread which hasn't been addressed for over a week, I'd really appreciate it. and most important if you could just respond to below. thank you I
how to send email please give me details with code in jsp,servlet
how to send email please give me details with code in jsp,servlet  how to send email please give me details with code in jsp,servlet
Send Email From JSP & Servlet
J2EE Tutorial - Send Email From JSP & Servlet...' are collected  by the servlet and then processed for sending the mail...,HttpServletResponse response)ADS_TO_REPLACE_20     throws
How to send boolean array to servlet from java application?
How to send boolean array to servlet from java application?  Hi, I want to send randomly generated array of boolean values. I used Random function and boolean array length to generate values. My question is I want to send
Java Servlet Problem - JSP-Servlet
, but in the attributeReplaced() method, i want to perform a redirect to another servlet. The events are being generated and captured, but to redirect to another page...Java Servlet Problem  I have a servlet class that implemets
How to Send particular error to another page in Servlet from web.xml
How to Send particular error to another page in Servlet from web.xml  How to Send particular error to another page in Servlet from web.xml  ...;/location> </error-page> You can also send error from Servlet
sendRedirect
; In send Redirect whenever the client makes any request it goes to the container, there the container decides whether the concerned servlet can handle the request or not.   If not then the servlet decides that the request can
How to redirect from a HTML page?
/ValidUser"); Here is an example of Send Redirect in Servlet. Thanks...How to redirect from a HTML page?  Hi, Is it possible to redirect from HTML page to another page on the net? I have one page and I want to redirect
How send different files to browser at same time ..example(pdf&html) want display in same request using servlet
How send different files to browser at same time ..example(pdf&html) want...(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { performTask(request, response); } protected void doPost
jsp or sevlet and html form to send picture to database - JSP-Servlet
jsp or sevlet and html form to send picture to database  Hello guys, thanks for your help. Please help me.. I want to insert student information... that will browse for the picture, jsp or servlet that the info from html will go
Exception: java.lang.IllegalStateException: getWriter() has already been called for this response - JSP-Servlet
Exception: java.lang.IllegalStateException: getWriter() has already been called for this response    response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); Statement st1
Java Servlet : SendRedirect
Java Servlet : SendRedirect In this tutorial, you will learn how to redirect Requests to Other Resources using SendRedirect in java servlet. SendRedirect() : Response provide method sendRedirect() which sends a redirect response
we want to send requiest to server by html select tag - JSP-Servlet
we want to send requiest to server by html select tag  how we can send requiest to server using html select tag. and pass the value also  Hi Request Information In JSP Request Method
request header and response - JSP-Servlet
request header and response - JSP-Servlet
servlet session - JSP-Servlet
login servlet fromabout us page now i want the servlet to redirect me... response (as a general servlet response...servlet session  hi, im working on a real estate web site.....n
Jsp redirect
Jsp redirect          In this section, you will learn how to redirect... response.sendRedirect() through which the server sends the response to the client
Sitemap Java Servlet Tutorial Section
parameter | Time Updater in Servlet | Send Redirect in Servlet ... | Send a Response Status in servlet | Read Cookies from Servlets | Send... Redirect in Servlet | Random Redirector | Servlet Context | Servlet
service method in servlet
service method in servlet In this tutorial you will learn about the service method in servlet that how can it be defined, how to get information from requests , and how the response can be constructed. service method is a method
Redirect page
Redirect page  In this code redirect tag is not work, so please help me ,how to redirect page in Tiles With JSTL . <%@ taglib prefix="tiles"uri="http://jakarta.apache.org/struts/tags-tiles" %> <%@ taglib prefix="c"uri
redirect with tiles - Struts
redirect with tiles  I have definition with three pages. I have link... specify in detail and send me code. Thanks.  I using tiles in struts 2. And i want redirect to other definition tag by url tag. Please help me
Servlet
Servlet  I want to know the steps to write a simple servlet program on windows without using any IDE and steps to run...please send me clear steps .   Hello Friend, Follow these steps: Put servlet-api.jar inside
diplay response
diplay response   Sir, How show sum of two tex boxes data to third box   Answer (adsbygoogle = window.adsbygoogle || []).push
how to send email
how to send email  hii i am new for jsp-servlet and i am making a project in jsp-servlet. i want to send the email after registration to client.please send me code that how to send mail after client registration. thank you
C:Redirect Tag - Struts
C:Redirect Tag  I am trying to use the jstl c:redirect tag... to the true start page of the web application. In performing the redirect, I want... information will have already been initialized. Is this possible with the c:redirect

Ads