hi... i have 1 jsp form. my form includes 6 text boxes and 8 dropdowns. I want to insert the data of these textboxe and dropdown to Database. I am using mysql server 5.1.The problem is that when I insert, a blank screen appears. (Data in dropdown is retrieved from the database).. please guide me accordingly or post a simple example using this type of situation. itz urgent.. :) thanku
Dani AI
Generated
Summary and quick diagnosis (based on the posts by , , and ): the page loads dropdowns from the database but submitting the form results in a blank page. The posted JSP mixes HTML and database logic and contains several patterns that commonly produce a silent failure (driver errors, uncaught exceptions, or runtime NPEs while closing resources). The replies asking to check the DB and server logs are the correct first directions.
Practical checklist and what to look for
- Inspect the servlet container log (Tomcat/GlassFish) for the full Java stack trace — that will pinpoint the failing line.
- Avoid executing the insert unconditionally on every request; run it only for POST submissions (or when a required parameter is present).
- Do not close resources without null checks. Closing a null PreparedStatement or Connection in a finally block will throw an exception that can hide earlier errors. Prefer try-with-resources.
- Ensure the JDBC driver jar is in WEB-INF/lib (or the server classpath). A missing driver will cause ClassNotFoundException if driver-loading is done outside a guarded try block.
- Remove or fix any undefined client-side handlers (the submit button’s undefined onclick can cause client-side errors; however, server-side logs will show server failures).
Minimal example pattern (use placeholders for DB URL/user/password and for actual column names):
if ("POST".equalsIgnoreCase(request.getMethod())) {
String sql = "INSERT INTO my_table(colA, colB) VALUES (?, ?)";
try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, request.getParameter("paramA"));
ps.setString(2, request.getParameter("paramB"));
int rows = ps.executeUpdate();
if (rows > 0) { out.println("Insert succeeded"); }
} catch (Exception e) {
e.printStackTrace(out); // debug-only: print full stack trace to page or server log
}
} Best-practice notes
- Move database access out of JSP into a servlet/DAO layer and use JSTL/EL for view rendering.
- Close ResultSet/Statement/Connection in the same scope or use try-with-resources.
- Keep debug stack traces off production pages; log them to the server log instead.
Following these checks will reveal whether the blank page is caused by an unhandled exception (most likely) or by a client-side problem.
Recommended Answers
Jump to Post— IIM 163@Neha - Have you checked in your DB if the data is inserted or not.If it is not inserted then was there any exception/error.
Provide us your code snippets and logs.
All 4 Replies
ruchi18 0 Light Poster
Do you wanna confirm from database side that is it your insert query is actully executing successfully or not?
What do you mean by blank page?
May be your code contains smthing which forward the response to that blank page.
can you post your code so that it will more clear?
IIM 163 Master Poster
@Neha - Have you checked in your DB if the data is inserted or not.If it is not inserted then was there any exception/error.
Provide us your code snippets and logs.
Neha2907 0 Newbie Poster
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%ResultSet resultset =null;%>
<html>
<head>
<title> loggingscreen </title>
</head>
<script>
function checkInput(){
var x=document.forms["loggingForm"]["Tno"].value;
if (x==null || x=="")
{
alert("Please enter Ticket No.");
return false;
}
var y=document.forms["loggingForm"]["otime"].value;
if (y==null || y=="")
{
alert("Please enter Open Time.");
return false;
}
var z=document.forms["loggingForm"]["brief_desc"].value;
if (z==null || z=="")
{
alert("Please enter the description of ticket.");
return false;
}
}
</script>
<body bgcolor="lavender">
<!-- ERROR SECTION STARTS: display errors here -->
<table border="0" >
<tr >
<td>
<font size="3" color="red">
<%
if(request.getAttribute("loginError")!=null){
out.println(request.getAttribute("loginError"));
}
%>
</font>
</td>
</tr>
</table>
<!-- Error section ENDS here -->
<form action="insert.jsp" method="post" name="loggingForm" onsubmit= "return checkInput()" >
<table border="0" bordercolor="gray" cellspacing="0" cellpadding="0" width="772" height="432" align="center">
<tr>
<td width="772" height="432" valign="middle" align="center">
<!-- begining of inner table -->
<table border="0" cellspacing="0" cellpadding="0" width="750" height="430" align="center">
<tr>
<td width="770" height="60" valign="top" align="center">
<!--
Name :header.jsp
Description :File to be included for header
-->
<table border="0" cellspacing="0" cellpadding="0" width="770" height="60" align="center">
<tr>
<td height="90" width="770" align="center">
<img src="ACES_LOGO.JPG" width="980" height="120">
</td>
</tr>
</table>
</td>
</tr>
<!-- end of header -->
<tr>
<td class="separator"></td>
</tr>
<tr>
<td width="770" height="20" valign="top"></td>
</tr>
<tr>
<td class="separator"></td>
</tr>
<tr>
<td width="770" height="20" valign="middle">
<table cellspacing="0" cellpadding="0" border="0" width="770">
<tr>
<td width="500" height="20" class="dataBlock">Log Tickets Here</td>
<td width="200" height="20" class="dataBlock"> Logged In</td>
<td width="70" height="20" class="dataBlock">
<a href="login.jsp"> SIGNOUT </a>
</td>
</tr>
</table>
</td>
</tr>
<!-- end of data block -->
<tr>
<td class="separator"></td>
</tr>
<tr>
<td width="770" height="370" valign="top">
<!-- start of workarea -->
<table border="1" cellspacing="0" cellpadding="0" width="760" height="25" align="center">
<table border="0" cellspacing="0" cellpadding="0" width="750" height="23" align="center">
<tr>
<td colspan="6" height="10"></td>
</tr>
<tr>
<td height="23" colspan="4" align="center" class="lastFormLabel"></td>
</tr>
</table>
<table border="0" cellspacing="0" width="750" cellpadding="0" align="left">
<tr>
<td height="23" width="214" class="leftTopFormLabel" align="right">Ticket No.  : </td>
<td><input type="text" value="" SIZE="24" name="Tno"></td>
<td height="23" width="154" class="leftTopFormLabel" align="right">WIP Time : </td>
<td><input type="text" value="" SIZE="24" name="Wtime"></td>
</tr>
</table>
<br><br>
<table border="0" cellspacing="0" width="750" cellpadding="0" align="left">
<tr>
<td height="23" width="214" class="leftTopFormLabel" align="right">Own By  : </td>
<td>
<select style="width:170px;" name="ownby">
<%
try{
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/aces_incident_management", "root", "wipro@123");
Statement statement = connection.createStatement() ;
resultset =statement.executeQuery("select * from aces_user_masters") ;
%>
<% while(resultset.next()){ %>
<option value=<%= resultset.getString(1)%>><%= resultset.getString(2)%></option>
<% } %>
</select>
</td>
<%
}
catch(Exception e)
{
out.println("wrong entry"+e);
}
%>
<td height="23" width="154" class="leftTopFormLabel" align="right">Resolution Time : </td>
<td width="192" height="23" class="leftTopFormLabel" align="left"><input type="text" value="" SIZE="24" name="Rtime"></td>
</tr>
</table><br><br>
<table border="0" cellspacing="0" width="750" cellpadding="0" align="left">
<tr>
<td height="23" width="214" class="leftTopFormLabel" align="right">Priority  : </td>
<td>
<select style="width:170px;" name="priority">
<%
try{
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/aces_incident_management", "root", "wipro@123");
Statement statement = connection.createStatement() ;
resultset =statement.executeQuery("select * from aces_priority_masters") ;
%>
<% while(resultset.next()){ %>
<option value=<%= resultset.getString(1)%>><%= resultset.getString(2)%></option>
<% } %>
</select>
</td>
<%
}
catch(Exception e)
{
out.println("wrong entry"+e);
}
%>
<td height="23" width="154" class="leftTopFormLabel" align="right">Module  : </td>
<td>
<select style="width:170px;" name="module">
<%
try{
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/aces_incident_management", "root", "wipro@123");
Statement statement = connection.createStatement() ;
resultset =statement.executeQuery("select * from aces_module_masters") ;
%>
<% while(resultset.next()){ %>
<option value=<%= resultset.getString(1)%>><%= resultset.getString(2)%></option>
<% } %>
<%
}
catch(Exception e)
{
out.println("wrong entry"+e);
}
%>
</select>
</td>
</tr>
</table><br><br>
<table border="0" cellspacing="0" width="750" cellpadding="0" align="left">
<tr>
<td height="23" width="214" class="leftTopFormLabel" align="right">Assignee Name  : </td>
<td>
<select style="width:170px;" name="assignee_name">
<%
try{
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/aces_incident_management", "root", "wipro@123");
Statement statement = connection.createStatement() ;
resultset =statement.executeQuery("select * from aces_assignee_masters") ;
%>
<% while(resultset.next()){ %>
<option value=<%= resultset.getString(1)%>><%= resultset.getString(2)%></option>
<% } %>
</select>
</td>
<%
}
catch(Exception e)
{
out.println("wrong entry"+e);
}
%>
<td height="23" width="154" class="leftTopFormLabel" align="right">Sub-Module  : </td>
<td>
<select style="width:170px;" name="sub_module">
<%
try{
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/aces_incident_management", "root", "wipro@123");
Statement statement = connection.createStatement() ;
resultset =statement.executeQuery("select * from aces_sub_module_masters") ;
%>
<% while(resultset.next()){ %>
<option value=<%= resultset.getString(1)%>><%= resultset.getString(2)%></option>
<% } %>
</select>
</td>
<%
}
catch(Exception e)
{
out.println("wrong entry"+e);
}
%>
</tr>
</table><br><br>
<table border="0" cellspacing="0" width="750" cellpadding="0" align="left">
<tr>
<td height="23" width="214" class="leftTopFormLabel" align="right">Primary Assignment  : </td>
<td WIDTH="186"><input type="text" value="ACES L2-L3 TEAM" SIZE="24" name="primary_assn"></td>
<td height="23" width="159" class="leftTopFormLabel" align="right">Category  : </td>
<td>
<select style="width:170px;" name="category">
<%
try{
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/aces_incident_management", "root", "wipro@123");
Statement statement = connection.createStatement() ;
resultset =statement.executeQuery("select * from aces_category_masters") ;
%>
<% while(resultset.next()){ %>
<option value=<%= resultset.getString(1)%>><%= resultset.getString(2)%></option>
<% } %>
</select>
</td>
<%
}
catch(Exception e)
{
out.println("wrong entry"+e);
}
%>
</tr>
</table></br><br>
<table border="0" cellspacing="0" width="750" cellpadding="0" align="left">
<tr>
<td height="23" width="214" class="leftTopFormLabel" align="right">Problem Status  : </td>
<td>
<select style="width:170px;" name="prob_status">
<option>Open</option>
<option>ReOpen</Option>
</select>
</td>
<td height="23" width="150" class="leftTopFormLabel" align="right">Sub Category  : </td>
<td width="192">
<select style="width:170px;" name="sub_category">
<%
try{
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/aces_incident_management", "root", "wipro@123");
Statement statement = connection.createStatement() ;
resultset =statement.executeQuery("select * from aces_sub_category_masters") ;
%>
<% while(resultset.next()){ %>
<option value=<%= resultset.getString(1)%>><%= resultset.getString(2)%></option>
<% } %>
</select>
</td>
<%
}
catch(Exception e)
{
out.println("wrong entry"+e);
}
%>
</tr>
</table></br><br>
<table border="0" cellspacing="0" width="750" cellpadding="0" align="left">
<tr>
<td height="23" width="214" class="leftTopFormLabel" align="right">Open Time : </td>
<td><input type="text" value="" SIZE="24" name="otime"></td>
<td height="23" width="154" class="leftTopFormLabel" align="right">Brief Description : </td>
<td><input type="text" value="" SIZE="24" name="brief_desc"></td>
</tr>
</table><br><br><br>
<table border="0" cellspacing="0" width="750" cellpadding="0" align="center">
<tr>
<td align="center"><input type="submit" value="   SUBMIT   " onclick="myFunction()" SIZE="24" name="SUBMIT"></td>
</tr>
</table>
</td>
</tr>
<!-- end of workarea-->
</table>
</table>
<!-- end of inner table -->
</td>
</tr>
</table>
<%
String Tno=request.getParameter("Tno");
String Wtime=request.getParameter("Wtime");
String ownby=request.getParameter("ownby");
String Rtime=request.getParameter("Rtime");
String priority=request.getParameter("priority");
String module=request.getParameter("module");
String assignee_name=request.getParameter("assignee_name");
String sub_module=request.getParameter("sub_module");
String primary_assn=request.getParameter("primary_assn");
String category=request.getParameter("category");
String prob_status=request.getParameter("prob_status");
String sub_category=request.getParameter("sub_category");
String otime=request.getParameter("otime");
String brief_desc=request.getParameter("brief_desc");
String connectionURL = "jdbc:mysql://localhost:3306/aces_incident_management";
Connection connection = null;
PreparedStatement pstatement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
try{
connection = DriverManager.getConnection
(connectionURL, "root", "wipro@123");
String queryString = " insert into aces_incident_details (Tno, Wtime, ownby, Rtime, priority, module, assignee_name, sub_module, primary_assn, category, prob_status, sub_category, otime, brief_desc) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
pstatement = connection.prepareStatement(queryString);
pstatement.setString (1, Tno);
pstatement.setString (2, Wtime);
pstatement.setString (3, ownby);
pstatement.setString(4, Rtime);
pstatement.setString (5, priority);
pstatement.setString (6, module);
pstatement.setString (7, assignee_name);
pstatement.setString (8, sub_module);
pstatement.setString(9, primary_assn);
pstatement.setString (10, category);
pstatement.setString (11, prob_status);
pstatement.setString (12, sub_category);
pstatement.setString(13, otime);
pstatement.setString (14,brief_desc);
updateQuery = pstatement.executeUpdate();
if (updateQuery != 0) { %>
<br>
<TABLE style="background-color: #E3E4FA;"
WIDTH="30%" border="1">
<tr><th>Data is inserted successfully
in database.</th></tr>
</table>
<%
}
}
catch (Exception ex) {
out.println("Unable to connect to batabase.");
}
finally {
// close all the connections.
pstatement.close();
connection.close();
}
%>
</form>
</body>
</html>
gian88r 0 Newbie Poster
you don't have an any codes??
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.