• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

response.sendRedirect()

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends,
When I use response.Redirect("url")I am being taken to the page specified however at the same time I am getting IOEception which I am catching.As a result I am unable to use it again and again.
Thanks in advance.
Regards,
Kavita.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we need to see the details of the IOException to understand that one.
Bill
 
Kavita Ghia
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,
The details of the IOException are as under:
HANDLER THREAD PROBLEM:java.io.IOException: Socket Closed
java.io.IOException:Socket Closed
at java.net.PlainSocketImpl.getInputStream(Unknown Source)
at java.net.Socket$1.run(Unknown Source)
at java.net.security.AccessController.doPrivileged(Native Method)
at java.net.Socket.getInputStream(Unknown Source)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)
com.sun.web.core.DefaultServlet:init
I am using JSWDK incase it helps and my prg. is as follows:
import java.sql.*;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class trial extends HttpServlet
{
private Connection dbConn=null;
private Statement st=null;
private ResultSet rs=null;
private String word=null;
private String query=null;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try
{
//load jdbc-odbc bridge
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//establish database connection to netsparsh
dbConn=DriverManager.getConnection("jdbc dbc:netsparsh");
System.out.println("connection established");
}
//thrown by Class.forName
catch(ClassNotFoundException e)
{
System.out.println("JDBC-ODBC bridge not found");
return;
}
catch(SQLException e)
{
System.out.println("SQL Exception thrown in init!");
}
System.out.println("At the end of init");
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException
{
System.out.println("In do Get OF trial Servlet");
if (req.getParameter("address")==null)
word="dias";
else
{
word=req.getParameter("address");
System.out.println(word);
}
try
{
st=dbConn.createStatement();
System.out.println("Statement created");
query="select membership_no,url from member where lcase(name)='"+(word)+"' ";
System.out.println(query);
rs=st.executeQuery(query);
System.out.println(rs);
if(rs.next()==true)
res.sendRedirect(rs.getString("url"));
else
res.sendRedirect("http://168.0.0.7:8080/netsparsh/notfound.html");
System.out.println("Redirect executed");
}
catch(SQLException _se)
{
System.out.println("Query not executed correctly");
}
}
public void destroy()
{
try
{
dbConn.close();
}
catch(SQLException se)
{
System.out.println("SQLException thrown in destory !");
}
}
}
 
Kavita Ghia
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Java Gurus,
Please reply to my query b'coz I am stuck at this point and its very important for me to complete my assignment on time.
Thanks in advance,
Kavita.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi kavita,
I tried out the code without openin the dbconnection and openin the recordsets. It worked fine didnt give me any exception. My guess would be close result set object i.e rs just before/after u redirect to the new url. rest of code looks fine.
Just try it out not sure.
Amit.

------------------
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic