Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet String Exception Program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragavendran.R
String Exception Program
2 Answer(s)      6 years and 4 months ago
Posted in : JSP-Servlet



Advertisement
View Answers

September 9, 2008 at 6:14 PM


Hi friend,

<%@ page language="java" %>
<HTml>
<HEAD>
<TITLE>Display file upload form to the user</TITLE></HEAD>

<BODY>
<A HREF = "loginForm.jsp"><b>Home</b></A>
<center>
<br><br><br>
<table border="1" bgcolor="bluelight" cellspacing="0" cellpadding="0">
<tr>
<td>
<FORM ENCTYPE="multipart/form-data" ACTION="FileUploadAction.jsp" METHOD=POST>
<center><colspan="2" align="center"><B>File upload into Database</B><center>

<center>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
<tr>
<td colspan="2" align="center">&nbsp;</td>
</tr>
<tr>
<td><b>Select file To Upload:</b></td>
<td><INPUT NAME="file" TYPE="file" size="50"></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>
</td>
</tr>
</table>
</center>
</body>
</html>



September 9, 2008 at 6:16 PM


<%@ page import="java.io.*,java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<html>
<%
int val =0;
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);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
System.out.println("saveFile=" + saveFile);
saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+ 1,saveFile.indexOf("\""));
System.out.println("saveFile" + saveFile);
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;

FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
%>

<%
Connection con=null;
PreparedStatement pstatement = null;
String line = null;
String value=null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String dbName = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName = "amar";
String password = "amar123";
try{
StringBuilder contents = new StringBuilder();
BufferedReader input = new BufferedReader(new FileReader(saveFile));
while (( line = input.readLine()) != null){
contents.append(line);
}
value = contents.toString();
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url+dbName,userName,password);
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) ;
String queryString = "INSERT INTO FileUpload set filename='"+value+"',filedate='"+strDateNew+"'";

pstatement=con.prepareStatement(queryString);
val = pstatement.executeUpdate();

if(val>0){
%>
<br><br>
<b>File <% out.println(saveFile); %> has been uploaded and inserted into Database at <%=strDateNew%>.</b>
<%
}

}
catch(Exception e)
{}
}
%>
</html>
---------------------------------------------------

Thanks & Regards

Amardeep


Related Tutorials/Questions & Answers:
String Exception Program - JSP-Servlet
String Exception Program  Respected Sir/Madam, I am... the JasperException StringIndexOutOfBound Exception- 54164.. I am sending the code for your kind reference: <% int val =0; String contentType
Out of bounce exception in the string reverse program - Java Beginners
Out of bounce exception in the string reverse program  In the given program below this is taken from ur site but when i am executing it.It is giving an exception like string out of bounce.So please give me the correct solution
Advertisements
string program
string program  write a program to print the pattern p r o program r a m
string program
string program  wap to find single occurrence of given string in java without using any predefined method
string program
string program  reads sentence and find the average length of word... AverageLengthOfWords { public static void main(String[] args...); System.out.print("Enter sentence: "); String st=input.nextLine(); String str
String program - Java Beginners
String program  write a program to accept a word. Pass it to the function magic(String x). The function checks the string for the presence... prints it is a magic string otherwise it prints not a magic string.  
Exception Handling-Error Messages in Program
Exception Handling-Error Messages in Program  Sorry about the first code block: import java.util.*; class GradeException extends Exception{ public GradeException(String s){ System.out.println(s); } } ----jGRASP exec: javac -g C
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
String reverse program
String reverse program  write a java program for reverse string? if the string is "Hi welcome to hyderabad" the reverse string is "hyderabad... for help. You can split the String into String array using split method of String
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
Program to swap the string
Program to swap the string  Hi, can any one tell me the code to swap...!!   Here is an example that prompts the user to enter two string and then swaps both the string without using third variable. import java.util.*; class
Exception Handling-Error Messages in Program
java.util.*; class GradeException extends Exception{ public GradeException(String s...Exception Handling-Error Messages in Program  Hi Friend, I am having trouble running this code as per my prior question on Exception handling
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
A Program To Reverse Words In String in Java
A Program To Reverse Words In String in Java  A Program To Reverse Words In String in Java for example: Input:- Computer Software Output... Tell Me This Program.  Here is an example that reverse the words
Reverse String Program in Java
Reverse String Program in Java We are going to describe about reverse string program in java. In this example reverses a string entered by the user. We... of the program: Enter a String Roseindia technology
Unhandled Exception
; that are thrown  during the execution of program. These exception are never caught during the execution of program. This result in nasty Exception stack. Usually this type... to catch each and every exception in the program. There are some unavoidable exception
Getting Exception on UseDefinedException sample program - Please help me how to resolve
Getting Exception on UseDefinedException sample program - Please help me how to resolve  class UseDefinedException extends Exception{ String msg...(String args[]) throws Exception { for(int i=1;i<=5;i
Program using String functions - Java Beginners
Program using String functions  Write a program to accept a sentence... { public static void main(String[] args) { int count = 0...); System.out.print("Enter string:"); String st = input.nextLine
exception
{ public static void main(String[] args)throws Exception { for (String s... arguments are not equalto two,throw a user defined exception "invalid parameter exception" ,otherwise display the two parameters.   Here is an example
exception
exception  example for numberformat exception   Hi Friend... main(String[] args) { try{ String st="Rose India...); } catch(Exception e){ System.out.println(e
exception
exception   Create a program that takes user name as input from user... defined checked exception ââ?¬Å?InvalidCharcterFoundExceptionââ?¬Â? and creater a block of codes that will handle the exception
Exception
Exception  whis is the Arithmetic Exception in java? or define Arithmetic Exception with exp?   Arithmetic Exception occurs, when you...(String args[]) { int d, a; try { d = 0; a = 42 / d; System.out.println
Exception
); } } public static void main(String args[])throws Exception { FooException oo=new...Exception  public class FooException extends Exception { public..."); } public FooException(String message) { super(message
exception
exception  wHEN RUNTIME EXCEPTION CLASS IS SUB OF EXCEPTION CLASS HOW CAN'T HANDLE UNCHECKED EXCEPTION
exception
exception  Identify the reason for SQLException exception, which... a row in the Status table: String str = "INSERT INTO Status VALUES...(String[] args){ try{ Class.forName("com.mysql.jdbc.Driver
 

 

 

DMCA.com