Forums
This topic is locked
java.lang.NullPointerException java.io.File.<init>(File.java:194)
29 Jan 2009 13:37:15 anju mol posted:
am getting the following errorHTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.lang.NullPointerException
java.io.File.<init>(File.java:194)
org.apache.jsp.testUpload_jsp._jspService(testUpload_jsp.java:328)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
My jsp files are
DbBlobFile.jsp
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN">
<html>
<%@ page import="java.io.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="oracle.jdbc.driver.*"%>
<%@ page import="oracle.sql.*"%>
<%! String inputBinaryFileName = null;%>
<%! File inputBinaryFile = null;%>
<%! String filename = null,sqlText=null;%>
<%! String outputBinaryFileName1 = null;%>
<%! File outputBinaryFile1= null;%>
<%! int position,chunkSize,bytesRead=0,bytesWritten=0,totbytesRead= 0,totbytesWritten=0;%>
<%! long blobLength;%>
<%! Connection conn=null;%>
<html>
<head>
File Attachment and Detachment Details
<style>
.font_appr
{
font-family: "Trebuchet MS", Trebuchet, Verdana, Helvetica, Arial, sans-serif;
font-size: 12px;
}
.progress-bar
{ /*border: 1px solid #56577A; */
/*width of the progress bar container*/
width: 100px;
margin: 5px;
padding: 1px;
background: #fff;
visibility: hidden;
}
.bar
{
height: 15px;
font-size: 11px;
/* indent the text off the screen as we don’t want to see the text anymore.*/
text-indent:-9000px;
}
</style>
<script type="text/javascript">
var count=0;
function busy()
{
var d=document.getElementById("bx_attachPurpose"
![](/images/forum/smilies/icon_smile_wink.png)
d.style.visibility="hidden";
//d.style.position="absolute";
//d.style.background="#DDFF33";
//d.style.opacity="40";
document.body.innerHTML+="<div id='sp1' style='position:absolute;top:0;left:0;width:100%;height:100%;background:#000000;filter:alpha(opacity=40);' for = 'sp1' >";
document.body.innerHTML+="
<label id='loading' style='position:absolute;top:0;left:435;background-color: FFFF66; width:115;height:30' >[size=4]Processing...</font></label>
";document.body.innerHTML+="</div>";
}
/*function cursor_wait()
{
document.body.style.cursor = 'wait';
}
function cursor_clear()
{
document.body.style.cursor = 'default';
}
*/
function generateRow()
{
if(count!=1)
{
var d=document.getElementById("div1"
![](/images/forum/smilies/icon_smile_wink.png)
d.innerHTML+="<label id='file2_label' style='position:absolute;top:240;left:35;width:131;height:18' for = 'label_file2' >File</label>";
d.innerHTML+="<input type=file name='txt_file' id='txt_file2' style='position:absolute;top:240;left:142;width:231;height:19'>";
d.innerHTML+="<input type='text' name='txt_fsd2' id='txt_fsd2' style='position:absolute;top:240;left:515;width:221;height:19'>";
d.innerHTML+="<label id='fsd1_label' style='position:absolute;top:240;left:405;width:131;height:18' for = 'label_fsd2' >File Description</label>";
d.innerHTML+="<input type=button name='btn_del' id='btn_del2' style='position:absolute;top:240;left:765;width:71;height:19' value='Delete' >";
d.innerHTML+="<label id='file3_label' style='position:absolute;top:280;left:35;width:131;height:18' for = 'label_file3' >File</label>";
d.innerHTML+="<input type=file name='txt_file' id='txt_file3' style='position:absolute;top:280;left:142;width:231;height:19'>";
d.innerHTML+="<input type='text' name='txt_fsd3' id='txt_fsd3' style='position:absolute;top:280;left:515;width:221;height:19'>";
d.innerHTML+="<label id='fsd3_label' style='position:absolute;top:280;left:405;width:131;height:18' for = 'label_fsd3' >File Description</label>";
d.innerHTML+="<input type=button name='btn_del' id='btn_del3' style='position:absolute;top:280;left:765;width:71;height:19' value='Delete' >";
d.innerHTML+="<label id='file2_labe4' style='position:absolute;top:320;left:35;width:131;height:18' for = 'label_file4' >File</label>";
d.innerHTML+="<input type=file name='txt_file' id='txt_file4' style='position:absolute;top:320;left:142;width:231;height:19'>";
d.innerHTML+="<input type='text' name='txt_fsd4' id='txt_fsd1' style='position:absolute;top:320;left:515;width:221;height:19'>";
d.innerHTML+="<label id='fsd4_label' style='position:absolute;top:320;left:405;width:131;height:18' for = 'label_fsd4' >File Description</label>";
d.innerHTML+="<input type=button name='btn_del' id='btn_del4' style='position:absolute;top:320;left:765;width:71;height:19' value='Delete' >";
d.innerHTML+="<label id='file5_label' style='position:absolute;top:360;left:35;width:131;height:18' for = 'label_file5' >File</label>";
d.innerHTML+="<input type=file name='txt_file' id='txt_file5' style='position:absolute;top:360;left:142;width:231;height:19'>";
d.innerHTML+="<input type='text' name='txt_fsd5' id='txt_fsd5' style='position:absolute;top:360;left:515;width:221;height:19'>";
d.innerHTML+="<label id='fsd5_label' style='position:absolute;top:360;left:405;width:131;height:18' for = 'label_fsd5' >File Description</label>";
d.innerHTML+="<input type=button name='btn_del' id='btn_del5' style='position:absolute;top:360;left:765;width:71;height:19' value='Delete' >";
count++;
}
}
/*
function sel_none()
{
for(var i=0;i<5;i++)
f.chk[i].checked=false;
}
function initialize()
{
var chks = document.getElementsByName('chk');
for(var i=0;i<5;i++)
{
var flag1=0;
if(chks[i].checked)
{
divId = 'sample'+i;
document.getElementById('prgrs'+i).style.visibility = 'visible';
var thedivId = document.getElementById( divId);
thedivId.style.backgroundColor="green";
brim(divId,0,'status'+i);
chks[i].checked=false;
var flag1=1;
}
}
}
function brim(Id,start,status)
{
if (document.getElementById)
{
o = document.getElementById(Id);
if(start <= 100)
{
if(start==100)
start=0;
setWidth(o, start); start += 1;
document.getElementById(status).innerHTML = "Uploading...";
window.setTimeout("brim('"+Id+"',"+start+",'"+status+"')",10);
}
else
document.getElementById(status).innerHTML = "Uploaded";
}}
function setWidth(o, start)
{ o.style.width = start;
}
function sel_all()
{
for(var i=0;i<5;i++)
f.chk[i].checked=true;
}
*/
function cr_time()
{
var myObject, f, date;
myObject = new ActiveXObject("Scripting.FileSystemObject"
![](/images/forum/smilies/icon_smile_wink.png)
f = myObject.GetFile(inputBinaryFileName);
date = f.DateCreated;
document.hiddenTextBox.value = date;
}
function fn()
{
alert("hai1"
![](/images/forum/smilies/icon_smile_wink.png)
form1.action="testUpload.jsp";
alert("hai2"
![](/images/forum/smilies/icon_smile_wink.png)
}
</script>
</head>
<body class="font_appr">
<form name="form1" id="f" method="post">
<div id="div1">
<label id="attachPurpose_label" style="position:absolute;top:80;left:35;width:131;height:17" for = "label_attachPurpose" >Attach Purpose</label>
<select name="bx_attachPurpose" id="bx_attachPurpose" style="position:Absolute;top:80;left:142;width:145;height:17">
<option value="" id="" selected > </option><option value="1" id="1"> Online </option>
<option value="2" id="2"> Offline </option></select>
<!--input type="radio" name="att_pur" id="online_rd" style="position:absolute;top:80;left:112;width:131;height:18" value="" >
<label id="online_label" style="position:absolute;top:80;left:185;width:131;height:17" for = "label_online">Online</label>
<input type="radio" name="att_pur" id="offline_rd" style="position:absolute;top:80;left:170;width:131;height:18"value="" >
<label id="offline_label" style="position:absolute;top:80;left:243;width:131;height:17" for = "label_offline">Offline</label-->
<!--input type="radio" id="online_rd" name="att_pur" style="position:absolute;top:79;left:167;" value="" >
<label id="online_label" style="position:absolute;top:80;left:185;width:131;height:17" for = "label_online">Online</label>
<input type="radio" name="att_pur"id="offline_rd" value="" style="position:absolute;top:79;left:225;">
<label id="offline_label" style="position:absolute;top:80;left:243;width:131;height:17" for = "label_offline">Offline</label-->
<label id="alertID_label" style="position:absolute;top:80;left:495;width:131;height:18" for = "alert_caseID" >AlertID</label>
<input type="text" name="txt_alertID" id="txt_alertID" style="position:absolute;top:80;left:555;width:131;height:19">
<label id="caseID_label" style="position:absolute;top:120;left:35;width:131;height:18" for = "label_caseID" >CaseID</label>
<input type="file" name="txt_caseID" id="txt_caseID" style="position:absolute;top:120;left:142;width:231;height:19">
<label id="file1_label" style="position:absolute;top:200;left:35;width:131;height:18" for = "label_file1" >File</label>
<input type="file" name="txt_file" id="txt_file1" style="position:absolute;top:200;left:142;width:231;height:19">
<label id="fsd1_label" style="position:absolute;top:200;left:405;width:131;height:18" for = "label_fsd1" >File Description</label>
<input type="text" name="txt_fsd" id="txt_fsd1" style="position:absolute;top:200;left:515;width:221;height:19">
<input type="button" name="btn_del" id="btn_del1" style="position:absolute;top:200;left:765;width:71;height:19" value="Delete" >
<input type="submit" name="btn_att" id="btn_att" style="position:absolute;top:30;left:765;width:71;height:19" value="Attach" onclick="fn()" >
<input type="button" name="btn_more" id="btn_more" style="position:absolute;top:30;left:845;width:71;height:19" value="More" onclick="generateRow(); cursor_wait();">
<input type="hidden" name="hiddenTextBox">
</div>
</form>
</body>
</html>
and
testUpload.jsp
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN">
<%@ page import="java.io.*"%>
<%@ page import="java.io.File"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="oracle.jdbc.driver.*"%>
<%@ page import="oracle.sql.*"%>
<%@ page import="java.util.Date"%>
<%!String inputBinaryFileName = null;%>
<%!File inputBinaryFile = null;%>
<%!String filename = null,sqlText=null;%>
<%!String outputBinaryFileName1 = null;%>
<%!File outputBinaryFile1= null;%>
<%!int position,chunkSize,bytesRead=0,bytesWritten=0,totbytesRead= 0,totbytesWritten=0,l=0,i=0;%>
<%!long blobLength,size;%>
<html>
<head>
File Attachment and Detachment Details
<style>
.font_appr
{
font-family: "Trebuchet MS", Trebuchet, Verdana, Helvetica, Arial, sans-serif;
font-size: 12px;
}
.progress-bar
{ /*border: 1px solid #56577A; */
/*width of the progress bar container*/
width: 100px;
margin: 5px;
padding: 1px;
background: #fff;
visibility: hidden;
}
.bar
{
height: 15px;
font-size: 11px;
/* indent the text off the screen as we don’t want to see the text anymore.*/
text-indent:-9000px;
}
</style>
<script type="text/javascript">
var count=0;
function busy()
{
var d=document.getElementById("bx_attachPurpose"
![](/images/forum/smilies/icon_smile_wink.png)
d.style.visibility="hidden";
document.body.innerHTML+="<div id='sp1' style='position:absolute;top:0;left:0;width:100%;height:100%;background:#000000;filter:alpha(opacity=40);' for = 'sp1' >";
document.body.innerHTML+="
<label id='loading' style='position:absolute;top:0;left:435;background-color: FFFF66; width:115;height:30' >[size=4]Processing...</font></label>
";document.body.innerHTML+="</div>";
}
function generateRow()
{
if(count!=1)
{
var d=document.getElementById("div1"
![](/images/forum/smilies/icon_smile_wink.png)
d.innerHTML+="<label id='file2_label' style='position:absolute;top:240;left:35;width:131;height:18' for = 'label_file2' >File</label>";
d.innerHTML+="<input type=file name='txt_file2' id='txt_file2' style='position:absolute;top:240;left:142;width:231;height:19'>";
d.innerHTML+="<input type='text' name='txt_fsd2' id='txt_fsd2' style='position:absolute;top:240;left:515;width:221;height:19'>";
d.innerHTML+="<label id='fsd1_label' style='position:absolute;top:240;left:405;width:131;height:18' for = 'label_fsd2' >File Description</label>";
d.innerHTML+="<input type=button name='btn_del' id='btn_del2' style='position:absolute;top:240;left:765;width:71;height:19' value='Delete' >";
d.innerHTML+="<label id='file3_label' style='position:absolute;top:280;left:35;width:131;height:18' for = 'label_file3' >File</label>";
d.innerHTML+="<input type=file name='txt_file3' id='txt_file3' style='position:absolute;top:280;left:142;width:231;height:19'>";
d.innerHTML+="<input type='text' name='txt_fsd3' id='txt_fsd3' style='position:absolute;top:280;left:515;width:221;height:19'>";
d.innerHTML+="<label id='fsd3_label' style='position:absolute;top:280;left:405;width:131;height:18' for = 'label_fsd3' >File Description</label>";
d.innerHTML+="<input type=button name='btn_del' id='btn_del3' style='position:absolute;top:280;left:765;width:71;height:19' value='Delete' >";
d.innerHTML+="<label id='file2_labe4' style='position:absolute;top:320;left:35;width:131;height:18' for = 'label_file4' >File</label>";
d.innerHTML+="<input type=file name='txt_file4' id='txt_file4' style='position:absolute;top:320;left:142;width:231;height:19'>";
d.innerHTML+="<input type='text' name='txt_fsd4' id='txt_fsd1' style='position:absolute;top:320;left:515;width:221;height:19'>";
d.innerHTML+="<label id='fsd4_label' style='position:absolute;top:320;left:405;width:131;height:18' for = 'label_fsd4' >File Description</label>";
d.innerHTML+="<input type=button name='btn_del' id='btn_del4' style='position:absolute;top:320;left:765;width:71;height:19' value='Delete' >";
d.innerHTML+="<label id='file5_label' style='position:absolute;top:360;left:35;width:131;height:18' for = 'label_file5' >File</label>";
d.innerHTML+="<input type=file name='txt_file5' id='txt_file5' style='position:absolute;top:360;left:142;width:231;height:19'>";
d.innerHTML+="<input type='text' name='txt_fsd5' id='txt_fsd5' style='position:absolute;top:360;left:515;width:221;height:19'>";
d.innerHTML+="<label id='fsd5_label' style='position:absolute;top:360;left:405;width:131;height:18' for = 'label_fsd5' >File Description</label>";
d.innerHTML+="<input type=button name='btn_del' id='btn_del5' style='position:absolute;top:360;left:765;width:71;height:19' value='Delete' >";
count++;
}
}
</script>
</head>
<body bgcolor="white" class="font_appr" onload="busy()">
<%
try {
String connectionURL = null;
Connection conn = null;
Statement stmt=null;
ResultSet rset=null;
String driver_class = "oracle.jdbc.driver.OracleDriver";
Class.forName(driver_class).newInstance();
connectionURL = "jdbc
![](/images/forum/smilies/icon_smile_shock.png)
conn = DriverManager.getConnection(connectionURL, "scott","tiger"
![](/images/forum/smilies/icon_smile_wink.png)
FileInputStream inputFileInputStream = null;
BLOB file=null;
byte[] binaryBuffer;
FileOutputStream outputFileOutputStream=null;
stmt = conn.createStatement();
conn.setAutoCommit(false);
String entityid="SUR00000001";
String caseid=request.getParameter("txt_caseID"
![](/images/forum/smilies/icon_smile_wink.png)
// String caseid=null;
String docname="DOCNAME";
String docid="DOCID";
String status="STATUS";
String statuscode="STATUSCODE";
String refid="REFID";
String att_purp=request.getParameter("bx_attachPurpose"
![](/images/forum/smilies/icon_smile_wink.png)
String user="CREATED USER";
String text_fsd=null;
String type=null;
String date1="29-jan-2009";
for(i=1;i<=5;i++)
{
if(i==1)
{
inputBinaryFileName = request.getParameter("txt_file1"
![](/images/forum/smilies/icon_smile_wink.png)
text_fsd=request.getParameter("txt_fsd1"
![](/images/forum/smilies/icon_smile_wink.png)
}
if(i==2)
{
inputBinaryFileName = request.getParameter("txt_file2"
![](/images/forum/smilies/icon_smile_wink.png)
text_fsd=request.getParameter("txt_fsd2"
![](/images/forum/smilies/icon_smile_wink.png)
}
if(i==3)
{
inputBinaryFileName = request.getParameter("txt_file3"
![](/images/forum/smilies/icon_smile_wink.png)
text_fsd=request.getParameter("txt_fsd3"
![](/images/forum/smilies/icon_smile_wink.png)
}
if(i==4)
{
inputBinaryFileName = request.getParameter("txt_file4"
![](/images/forum/smilies/icon_smile_wink.png)
text_fsd=request.getParameter("txt_fsd4"
![](/images/forum/smilies/icon_smile_wink.png)
}
if(i==5)
{
inputBinaryFileName = request.getParameter("txt_file5"
![](/images/forum/smilies/icon_smile_wink.png)
text_fsd=request.getParameter("txt_fsd5"
![](/images/forum/smilies/icon_smile_wink.png)
}
//Retrieving Full path of file############################################
String f_path=inputBinaryFileName;
//Getting the size of the file#############################################
File f =new File(inputBinaryFileName);
size=f.length()/1024;
out.print(size);
//Retrieving the file name only############################################
l= inputBinaryFileName.lastIndexOf('\\');
filename= inputBinaryFileName.substring(l+1);
//Getting the File Type################################################
int index= filename.lastIndexOf('.');
type= inputBinaryFileName.substring(l+1);
//############################################################
inputBinaryFile = new File(inputBinaryFileName);
if (!inputBinaryFile.exists())
{
throw new IOException("File not found. " + inputBinaryFileName);
}
outputBinaryFileName1 = inputBinaryFileName + ".getBytes.out";
inputBinaryFile = new File(inputBinaryFileName);
inputFileInputStream = new FileInputStream(inputBinaryFile);
//Inserting into db################################################
sqlText = "INSERT INTO SUR_CASEDOCDTLS"+
"VALUES("+
" '" +entityid+ "', " +
" '" +caseid+ "', " +
" '" +docname+ "', " +
" '" +docid+ "', " +
" '" +statuscode+ "', " +
" '" +status+ "', " +
"EMPTY_BLOB(), " +
" '" +refid+ "', " +
" '" +i+ "', " +
" '" +size+ "', " +
" '" +user+ "', " +
" '" +att_purp+ "', " +
" '" +text_fsd+ "', " +
" '" +type+ "', " +
" '" +date1+ "', " +
" '" +inputBinaryFileName+ "', " +
" '" +filename+ "', " +
" '" +i+ "', " +
" SYSDATE " +
" )";
stmt.executeUpdate(sqlText);
sqlText ="SELECT CASEDOCUMENT FROM SUR_CASEDOCDTLS WHERE ID = "+i+" " +"FOR UPDATE";
rset = stmt.executeQuery(sqlText);
rset.next();
file = ((OracleResultSet) rset).getBLOB("CASEDOCUMENT"
![](/images/forum/smilies/icon_smile_wink.png)
chunkSize = file.getChunkSize();
binaryBuffer = new byte[chunkSize];
position = 1;
while ((bytesRead = inputFileInputStream.read(binaryBuffer)) != -1)
{
position += bytesRead;
totbytesRead += bytesRead;
totbytesWritten += bytesWritten;
}
inputFileInputStream.close();
conn.commit();
rset.close();
conn.close();
} //try closing here###############################
catch (IOException e)
{
out.println("Caught I/O Exception: (Write BLOB value - Stream Method)."
![](/images/forum/smilies/icon_smile_wink.png)
e.printStackTrace();
throw e;
}
catch (SQLException e)
{
out.println("Caught SQL Exception: (Write BLOB value - Stream Method)."
![](/images/forum/smilies/icon_smile_wink.png)
out.println("SQL:\n" + sqlText);
e.printStackTrace();
throw e;
}
%>
<div id="div1">
<label id="attachPurpose_label" style="position:absolute;top:80;left:35;width:131;height:17" for = "label_attachPurpose" >Attach Purpose</label>
<select name="bx_attachPurpose" id="bx_attachPurpose" style="position:absolute;top:80;left:142;width:145;height:17" >
<option value="" id="" selected ></option>
<option value="1" id="1"> Online</option>
<option value="2" id="2"> Offline</option>
</select>
<!--input type="radio" name="att_pur" id="online_rd" style="position:absolute;top:80;left:112;width:131;height:18" value="" >
<label id="online_label" style="position:absolute;top:80;left:185;width:131;height:17" for = "label_online">Online</label>
<input type="radio" name="att_pur" id="offline_rd" style="position:absolute;top:80;left:170;width:131;height:18"value="" >
<label id="offline_label" style="position:absolute;top:80;left:243;width:131;height:17" for = "label_offline">Offline</label-->
<!--input type="radio" id="online_rd" name="att_pur" style="position:absolute;top:79;left:167;" value="" >
<label id="online_label" style="position:absolute;top:80;left:185;width:131;height:17" for = "label_online">Online</label>
<input type="radio" name="att_pur"id="offline_rd" value="" style="position:absolute;top:79;left:225;">
<label id="offline_label" style="position:absolute;top:80;left:243;width:131;height:17" for = "label_offline">Offline</label-->
<label id="alertID_label" style="position:absolute;top:80;left:495;width:131;height:18" for = "alert_caseID" >AlertID</label>
<input type="text" name="txt_alertID" id="txt_alertID" style="position:absolute;top:80;left:555;width:131;height:19">
<label id="caseID_label" style="position:absolute;top:120;left:35;width:131;height:18" for = "label_caseID" >CaseID</label>
<input type="file" name="txt_caseID" id="txt_caseID" style="position:absolute;top:120;left:142;width:231;height:19">
<label id="file1_label" style="position:absolute;top:200;left:35;width:131;height:18" for = "label_file1" >File</label>
<input type="file" name="txt_file1" id="txt_file1" style="position:absolute;top:200;left:142;width:231;height:19">
<label id="fsd1_label" style="position:absolute;top:200;left:405;width:131;height:18" for = "label_fsd1" >File Description</label>
<input type="text" name="txt_fsd1" id="txt_fsd1" style="position:absolute;top:200;left:515;width:221;height:19">
<input type="button" name="btn_del" id="btn_del1" style="position:absolute;top:200;left:765;width:71;height:19" value="Delete" >
<input type="button" name="btn_att" id="btn_att" style="position:absolute;top:30;left:765;width:71;height:19" value="Attach" onclick=" busy();">
<input type="button" name="btn_more" id="btn_more" style="position:absolute;top:30;left:845;width:71;height:19" value="More" onclick="generateRow(); cursor_wait();">
<input type="hidden" name="hiddenTextBox">
</div>
</body>
</html>
Can anyone help me.......?[:0][:0][:0]
Thanks in advance.......
Edited by - on 29 Jan 2009 13:40:03