jsp error

jsp error

To Upload and insert the file into oracle Database with Current Date and Time In JSP
and my project is online library management system plz help how to store some books in particular folder and after how retrive books in that folder urgentlyyyyyyy
View Answers

August 17, 2010 at 1:12 PM

Hi Friend,

We have used Mysql database.
Try the following code:

1)page.jsp:

<%@ page language="java" %>
<HTML>
<HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>
<BODY> <FORM ENCTYPE="multipart/form-data" ACTION="upload.jsp" METHOD=POST>
<br><br><br>
<center>
<table border="0" bgcolor=#ccFDDEE>
<tr><center><td colspan="2" align="center"><B>UPLOAD THE FILE</B><center></td></tr>
<tr><td colspan="2" align="center">&nbsp;</td></tr>
<tr><td><b>Choose the file To Upload:</b></td><td><INPUT NAME="file" TYPE="file"></td></tr>
<tr><td colspan="2" align="center">&nbsp;</td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Send File"> </td></tr>
<table>
</center>
</FORM>
</BODY>
</HTML>

2)upload.jsp:

<%@ page import="java.io.*,java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<%
String saveFile="";
String contentType = request.getContentType();
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
saveFile="C:/UploadedFiles/"+saveFile;
File ff = new File(saveFile);
FileOutputStream fileOut = new FileOutputStream(ff);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
%><Br><table border="2"><tr><td><b>You have successfully upload the file by the name of:</b>
<% out.println(saveFile);%></td></tr></table>
<%
java.util.Date now = new java.util.Date();
String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
String strDateNew = sdf.format(now) ;
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/test";;
ResultSet rs = null;
PreparedStatement psmnt = null;
FileInputStream fis;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
File f = new File(saveFile);
psmnt = connection.prepareStatement("insert into file(file_data,file_Date) values(?,?)");
fis = new FileInputStream(f);
psmnt.setBinaryStream(1, (InputStream)fis, (int)(f.length()));
psmnt.setString(2,strDateNew);
int s = psmnt.executeUpdate();
if(s>0) {
System.out.println("Uploaded successfully !");
}
else{
System.out.println("unsucessfull to upload file.");
}
}
catch(Exception e){e.printStackTrace();}
}
%>
<a href="viewFiles.jsp">View Files</a>

August 17, 2010 at 1:14 PM

continue....

3)viewFiles.jsp:

<%@page import="java.io.*"%>
<table>
<%
File f = new File("C:/UploadedFiles");
File[] files = f.listFiles();
for(int i=0;i<files.length;i++){
String name=files[i].getName();
String path=files[i].getPath();
%>
<tr><td><%=name%></td><tr>
<%
}
%>
</table>

For the above code, we have used following database table:

CREATE TABLE `file` (
`file_id` bigint(30) NOT NULL auto_increment,
`file_data` longblob,
`file_Date` datetime default NULL,
PRIMARY KEY (`file_id`)
)

Thanks









Related Tutorials/Questions & Answers:
JSP error
JSP error  what is difference between global-exception and error-page in jsp. which condition they are use
jsp error
jsp error  <p>hi, could please help whenever i run jsp file in my eclipse i got this error.my jsp file is</p> &lt;%@ page language... encountered an internal error () that prevented it from fulfilling this request
Advertisements
jsp error - JSP-Servlet
jsp error  HTTP Status 404 - /jsp... message /jsp/ description The requested resource (/jsp/) is not available..., The 404 or Not Found error message is an HTTP standard response code indicating
JSP Error - JSP-Servlet
JSP Error  When i am running my registration.jsp getting following error. HTTP Status 500... description The server encountered an internal error () that prevented it from fulfilling
jsp error - JSP-Servlet
jsp error  Hello, my name is sreedhar. i wrote a jsp application to generate a report from oracledata base and the report should display in Ms-excel... in detail. Visit for more information. http://www.roseindia.net/jsp/ Thanks
jsp error - JSP-Servlet
jsp error  how to remove below error:: exception org.apache.jasper.JasperException: java.lang.NullPointerException root cause...... newpo.jsp:   JSP Page
jsp error - JSP-Servlet
jsp error  To Upload and insert the file into oracle Database with Current Date and Time In JSP and my project is online library management system plz help how to store some books in particular folder and after how retrive
JSP error page - JSP-Servlet
JSP error page  Hi i have 1000 of JSP. but we coded it without adding... the exception occured in JSP. is there any short cut i can do? do not want to add this line.../DAO/bean layer and not in the JSP. let me know if you have any idea. Thanks
JSP Translation error - JSP-Servlet
JSP Translation error  Hello friends, In a new file declared first variable shows the following error. ----------------------------------------------- An error occurred at line: 2 in the jsp file: /stud
jsp runtime error - JSP-Servlet
jsp runtime error  sir, when i am running ur prog... from this website.... http://www.roseindia.net/jsp/poi/readingWriting.shtml i did the same as per guidelines...but i got error..!!!! org.apache.jasper.JasperException
Servlet Error - JSP-Servlet
/lib folder if database is mysql. servlet-api.jar jsp-api.jar mysql-connector.... Error showing ==>Admin/FirstServlet is not a servlet Sincerely Prakash   Hi prakash servlet-api.jar jsp-api.jar mysql-connector
jsp code error - JSP-Servlet
jsp code error  hello, is anyone here who can solve my problem. what happen experts where r u? r u not able to do
jsp code error - JSP-Servlet
jsp code error  hello, is anyone here who can solve my problem. what happen experts where r u? or u r not able to do
jsp error - JDBC
jsp error   in this code the else part is nt executing atall... of that a error is like-----------"java.sql.SQLException: [Microsoft][ODBC Driver Manager... the line is not getting incremented u r getting that error just do this change
JScript error - JSP-Servlet
JScript error  Hello friends, I am doing jsp... logins while updating profile it will not show any error. But, in many logins it shows error as unterminated string. I am not able
jsp code error - JSP-Servlet
jsp code error  I have a jsp page named "tMastDepartment".which has some table row containing text box like 'project code','Departmentcode','employee_id', 'address', and 'city' and a one dropdown list which contains department
jsp-Hibernate Error - JSP-Servlet
jsp-Hibernate Error  hi, my problem is, I designed an Interface where i am tring to listing the all rows of a table using Iterator and putted a link for deleting each row. I am deleteing row using row id of that record.it delete
Script error - JSP-Servlet
running this it shows an error as "STACK OVERFLOW". Correct the code . The code... any problem then send me jsp code. Thanks
JSP SQL Error
JSP SQL Error  Hi While trying to execute the below code i'm getting the following error "java.sql.SQLException: Io exception: Got minus one from a read call ". please help me out. <% try{ String Username
jsp-servelet,error http404
jsp-servelet,error http404  I am using mysql commandclient to connect with eclipse using jsp and servelet. I keep getting the error hhtp 404. Register.jsp Name:<input type="text" name="userName"/><
Jsp Error - Development process
Jsp Error  Hi, While executing Add_Data.jsp , am getting following error. "Data type mismatch in criteria expression." "View_Data.jsp...) at jsp_servlet.__add_data._jspService(__add_data.java:146
jsp-Hibernate Error - Hibernate
jsp-Hibernate Error  hi, my problem is, I designed an Interface where i am tring to listing the all rows of a table using Iterator and putted a link for deleting each row. I am deleteing row using row id of that record.it delete
Programming Error - JSP-Servlet
(""); } catch(SQLException se) { out.println("Database Error :"+se.getMessage()); } catch(Exception e) { out.println("General Error :"+e.getMessage... ServletException,IOException {doPost(req,res);} } There is some error
JSP Error 500
JSP Error 500          JSP Error 500 is to generate error status 500 in jsp.  The Error 500 occurred when the server encounter an internal error
Jsp Error - Development process
Jsp Error  Hi, While executing following code "View_Service.jsp" , am getting Internal Server Error java.sql.SQLException: [Microsoft][ODBC...(JdbcOdbcStatement.java:288) at jsp_servlet.__add_data._jspService(__add_data.java:146
Programming Error - JSP-Servlet
is access). Then how to do this in jsp?? Please Reply me?? Please do Reply
Programming Error - JSP-Servlet
statement in jsp i want to calculate the price of placing ad according to user
Programming Error - JSP-Servlet
("http://localhost:8080/examples/jsp/modify.jsp?filename="+filename
Programming Error - JSP-Servlet
Programming Error  How to validate login page using jsp where it checks for username whether it is empty or not or is it including number or not if it is the paste alert message.   Hi Friend, Try the following
insertion error - JSP-Servlet
insertion error  my first jsp page : In this i m getting all the values through a method called getAllDetails,the values are getting inserted... into table. below is the codeof jsp and java pages; function
Programming Error - JSP-Servlet
is it possible in jsp. when user types some thing in draft ad textarea
JSP Page Error
JSP Page Error  Hello Sir. I m using Oracle 10g as a database n tomcat server DSN name : NB Username NB Password EBS Table name consumer When i run jsp page on the browser it only shows the code nothing else.. I have
JSP Page Error
JSP Page Error  Hello Sir. I m using Oracle 10g as a database n tomcat server DSN name : NB Username NB Password EBS Table name consumer When i run jsp page on the browser it only shows the code nothing else.. I have
JSP Page Error
JSP Page Error  Hello Sir. I m using Oracle 10g as a database n tomcat server DSN name : NB Username NB Password EBS Table name consumer When i run jsp page on the browser it only shows the code nothing else.. I have
Tomcat error - JSP-Servlet
the error :-this is non microsoft product please see event log . what might be the reason of such error  HI, Can you paste the error log here.We
output error - JSP-Servlet
output error  /*hi friends, the given below is my servlet program error? How can i solve this problem? */ HTTP Status 500... report message description The server encountered an internal error
error message - JSP-Servlet
error message  hi, friends after complete my servlet programe i can type http://localhost:8080 on the browser. the servlet program is insert data into dbms. but i have errormessage that is "window can not access the specified
Programming Error - JSP-Servlet
(); } } }//End of class m geeting error in this can u please tell me whats the error nd how to solve
Error output - JSP-Servlet
Error output  Can anyone please assist me; The printed output should be: The product is 10. But instead of it I got; The product is undefined. Can anyone trace what went wrong of my code pls
Programming Error - JSP-Servlet
integer.parseInt but its giving error. Please Reply me . Thank you
code error - JSP-Servlet
is error in this progrm. ss function describe() { window.status
Programming Error - JSP-Servlet
??? And when i tried its giving me error than cannot find variable.In
JSP Error Page
JSP Error Page          JSP Error Page is used to specify the custom error page and runtime error occurs with an exception being thrown, the custom
Proogramming Error - JSP-Servlet
, ChequeAmt ,BankName shoukd get validated but i tried its getting error sir can u
SQL error - JSP-Servlet
){ System.out.println("Error occured while updating!!!"); } con.close
Programming error - JSP-Servlet
"); } catch(SQLException se) { out.println("Database Error :"+se.getMessage()); } catch(Exception e) { out.println("General Error :"+e.getMessage()); } %>
Programming error - JSP-Servlet
Programming error  Actually there is an error in placeorder.jsp file where there are 5 fields OrderNo ,Name , Address, Email, PhoneNo where if I delete an order of client based on orderno then suppose in database if there are 5
Error in Jsp - Development process
Error in Jsp  Hi Friends, For the following code when i include src in script Sub-Combo box is not working . but if i remove src then it will work. Add Data var arr = new Array(); arr["Select"] = new Array
Programming error - JSP-Servlet
where if @ is not given or (dot). is not given etc then it should display error
Error in loading jsp file - JSP-Servlet
Error in loading jsp file  I did as u have said. I copied iitem.jsp in webapps\examples\jsp and item.java in webapps\examples\WEB-INF\classes\form...:8080/webapps/examples/jsp/iitem.jsp In both cases,it is giving the following error

Ads