Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-06-2008, 09:05 AM   PM User | #1
guravharhsa
New to the CF scene

 
Join Date: Jul 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
guravharhsa is an unknown quantity at this point
problem while forwarding toward the error page.

Hi,
in my jsp page when sql exception occurs, i forward to the page error.jsp to display the message. but it not working . here is an page
Code:
<%-- 
    Document   : groupaddok
    Created on : Aug 4, 2008, 4:20:31 PM
    Author     : user1
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language ="java" %>
<%@ page errorPage="errorpage.jsp" %>
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*,java.io.*,java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>add user</title>
        <link rel="stylesheet" href="styles/styles.css" type="text/css"> 
    </head>
    <body>
         <table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td><%@ include file="/includes/logohead.jsp" %></td>
</tr> 
<tr><td><%@ include file="/toplinks.jsp"%></td></tr>
<tr><td width="100%" valign="top">
<table width="100%" cellspacing="0" cellpadding="0" border="1" borderColor=#000066>
    <tr>
<td width="80%">&nbsp;&nbsp;&nbsp;
    
    <table border="1" width="50%" cellpadding="0" cellspacing="0" align="center" bordercolor="#B0C4DE">
       <% 
    String DESCRIPTION = request.getParameter("desc");   
            
     String connectionURL = "jdbc:mysql://localhost:3306/mynewdatabase";
   
     Connection connection = null;   
     PreparedStatement pstatement = null;
   
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     int updateQuery = 0;
     
	
	 if(DESCRIPTION!=null){		
	     if(DESCRIPTION!="") {
            try {            
              
              connection = DriverManager.getConnection
              (connectionURL, "root", "root123");
             
              String queryString = "INSERT INTO groupid(description) VALUES (?)";
	      pstatement = connection.prepareStatement(queryString);
               pstatement.setString(1,DESCRIPTION );
              
              updateQuery = pstatement.executeUpdate();
              //out.println("Q.="+updateQuery);
              if (updateQuery != 0) { %>
	          
		   
              <%
             
            }
              }
            
            catch (Exception ex) {
           // out.println("a"+ex.getMessage());    
           // out.println("Unable to connect to batabase.");
   
            }
            finally {
                pstatement.close();
                connection.close();
            }
	  }
	}
       %>
   <tr><td width="60%" class="StripFinalbold" ><font class="Fontfinalbold">The Group <%=DESCRIPTION%>  are added into Database.</font></td></tr></table>
</td></tr></table></td></tr>
   </table>
    </body>
</html>
and here is an error.jsp page

Code:
<%-- 
    Document   : errorpage
    Created on : Aug 5, 2008, 4:34:03 PM
    Author     : user1
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page isErrorPage="true" import="java.io.*,java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
<%-- Exception Handler --%>
<font color="red">
    <P> THE ENTRY<%= exception.toString()%> ARE DUPLICATE IN  DATABASE</p><br>
</font>
<%
out.println("<!--");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
out.print(sw);
sw.close();
pw.close();
out.println("-->");
%>

<p> here is an test </p>

    </body>
</html>
Any suggestion is highly appreciated
Thanks and Regards
haresh
guravharhsa is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:58 PM.


Advertisement
Log in to turn off these ads.