Home Answers Viewqa JSP-Servlet Servlet Response Send Redirect

 
 


john
Servlet Response Send Redirect
2 Answer(s)      3 years ago
Posted in : JSP-Servlet

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 Pages:
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
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... entered by the user is correct then the servlet will redirect the request
Send a Response Status in servlet
; This section illustrates you how to send response status in servlet. All... example shows how a response has been send from the servlet. If the requested... .style1 { font-weight: bold; } Send a Response
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
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
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/>
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
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
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
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
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
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
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
Server_Gives_Null_Response
project i m able to establish the connection and to send the req from client at port 6066. My Problem is that when i send response from server (port 6066... the server. Kindly give the solution how can i get response at client class. I
Send Email From JSP & Servlet
J2EE Tutorial - Send Email From JSP & Servlet...; by the servlet and then processed for sending the mail...(HttpServletRequest request,HttpServletResponse response)    
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
JSP implicit object "response"
","text/html"); sendRedirect(String): This method is used to send a response... method = "post" action = "response-redirect-main.jsp"...; </body> </html> response-redirect-main.jsp <
Send Cookies in Servlets
, a servlet create cookie and add the cookie to the response header with method... Send Cookies in Servlets       This section illustrates you how to send cookie
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
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
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
ZF Page Redirect
Redirect to another page using submit button, in ZF: It is one of the most common activity in a web application to redirect one web page to another web page. We will learn how to redirect page in Zend Framework form. As we have
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
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
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
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
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
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
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
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
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
servlet
(); //send response to browser String acc_num=request.getParameter... com.ilp.tsi.um.bean.BankBean; import com.ilp.tsi.um.service.BankService; /** * Servlet..., HttpServletResponse response) */ protected void doPost(HttpServletRequest request
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
Using tag <c:redirect> of Core JSTL tags
tag <c:redirect> that is used to redirect the page to given url, here...://java.sun.com/jsp/jstl/core" %> redirect_CoreJstl.jsp <...; <c:redirect url="http://www.roseindia.net"/> <
How to use filter to redirect to login page after session timeout
How to use filter to redirect to login page after session timeout  ... then automatically it should redirect to login page from where user has to login again... != null && !session.isNew()) { chain.doFilter(request, response
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
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
getOutputStream() has already been called for this response
). help me how to solve this issue? Servlet.service() for servlet action threw... called for this response. here is my jsp code: <%@ page import... form, HttpServletRequest request, HttpServletResponse response
Sitemap Java Servlet Tutorial Section
parameter | Time Updater in Servlet | Send Redirect in Servlet ... a Response Status in servlet | Read Cookies from Servlets | Send Cookies... | Servlets Links | Select Color | sendRedirect | Send Redirect
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
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
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
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
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
Servlet Redirecting - JSP-Servlet
Servlet Redirecting  Hi I have made a main page with User name...*; public class Slogin extends HttpServlet implements Servlet { public void... = req.getParameter("pwd"); //Redirect call to another url

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.