saravanan
servlet/jsp
1 Answer(s)      4 years and 2 months ago
Posted in : JSP-Servlet

View Answers

March 24, 2009 at 1:19 AM


Hi friend,

Code to help in solving the problem :

"uploadfile.html"

<html>
<head><title>File Upload</title></head></p> <p><body>
<form action="uploadfile.jsp" method="post" enctype="multipart/form-data" name="form1" id="form1">
<center>
<table border="2">
<tr>
<td align="right"><b>File Upload</td>
<td>
<input name="file" type="file" id="file">
<td>
</tr>

<tr>
<td align="center">
<input type="submit" name="Submit" value="Submit"/>
<input type="reset" name="Reset" value="Reset"/>

</td>
</tr>
</table>
</center>
</form>
</body>
</html>

"uploadfile.jsp"

<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.io.File" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<%!

int count1=0,count2=0,count3=0,count4=0,count5=0;
%>
<%
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
} else {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
e.printStackTrace();
}
Iterator itr = items.iterator();
while (itr.hasNext())
{
FileItem item = (FileItem) itr.next();

try {

String itemName = item.getName();
File savedFile = new File(config.getServletContext().getRealPath("/")+"uploadfile\\"+itemName);
item.write(savedFile);

} catch (Exception e) {
e.printStackTrace();
}

}
}
%>
<center><h1>Your File has been Uploaded</h1></center>

Thanks









Related Pages:
How to call servlet in JSP?
How to call servlet in JSP?  How to call servlet in JSP
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
servlet and jsp
servlet and jsp  how to connect an jsp and an servlet without connecting to database
Servlet,Jsp
Servlet,Jsp   This is my requirement?I have a login page and register page?If I give the url as http://localhost:8080/Project/Login.jsp ,it should go to login page?.then from login page on click of register button I can register
servlet and jsp
servlet and jsp  how can i get a form question from a database... with servlets and jspīs   Have a look at the following links: http://www.roseindia.net/jsp/paging.shtml http://www.roseindia.net/jsp/navigation
SERVLET AND JSP
SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links: http://www.roseindia.net/jsp/user...://www.roseindia.net/answers/viewqa/JSP-Servlet/16413-using-insert-and-delete-in-a-single
SERVLET AND JSP
SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links: http://www.roseindia.net/jsp/user...://www.roseindia.net/answers/viewqa/JSP-Servlet/16413-using-insert-and-delete-in-a-single
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
servlet - JSP-Servlet
be the xml code which will describe a servlet and mapps an instance of it with specific url..???  Hi friend, Servlet and JSP Examples. Servlet and JSP Examples
servlet - JSP-Servlet
servlet  please post me some attractive learn simple steps tutoriols jsp&servlet with source code or example with netbeans. post all servlet and jsp simple example chapter by chapter who will build my knowldge very fastly
atm code in servlet& jsp
atm code in servlet& jsp  pls send me the code of ATM project in servlet jsp . my requirements are first of all an user login window open then balance enquiry, withdraw of money, money transfer, then log out. pls send as early
servlet/jsp - JSP-Servlet
servlet/jsp  hi, get me the source code to upload all file formats in servlet/jsp plaese help me as soon as possible its urgent!!! by saravanan.k  Hi friend, Code to help in solving the problem
servlet - JSP-Servlet
Inserting values in servlet and jsp  How to Insert the values into database table using Servlet and JSP?  Insert the values into database table using Servlet and JSP.Code ExampleDataInsertionExam.javaimport java.io.
About jsp and Servlet - JSP-Servlet
About jsp and Servlet  Servlets are directly using java technologies. It is used in HTTP,FTP..etc, But Jsp only used in HTTP. Servlets are running fastly... Then why we moved from Servlet to JSP.. Pl Tell me the reasons
EJB and Servlet - JSP-Servlet
EJB and Servlet  hi all; I Have some Question regarding the EJB and servlet, How can we communicates servlet and EJB? can u give me a sample Code how to connect my servlet to ejb.. ty   Hi Friend
servlet - JSP-Servlet
servlet  http://localhost:8080/collegeapp/Avanthi.html after complition of my servlet program, i typed in the above url, then small window is displayed in my monitor, it asks connect to localhost, enter user name
Servlet - JSP-Servlet
Deploy the application Servlet  How to deploy my application in Servlet?  Hi,you can put yours applet .class in in one folder simillarly put all of your jsps in in other folder.in the plugin tag in the jsp page mention
jsp/servlet - JSP-Servlet
jsp/servlet  How to create and save the excel file on given location using jsp/servlet?  hi Geetanjali, Read for more information, http://www.roseindia.net/jsp/poi/excelPOI.shtml Thanks
servlet - JSP-Servlet
servlet  Develop a web page using Servlet for session tracking which ask for your name and address and print a message of welcome along with the number of times you have visited the page. If you are visiting the page first time
Servlet and Jsp - JDBC
Servlet and Jsp  Hai I need a program to update the table records ......The program should have only update code.....It shouldnot combine with Add or delete code. It is very urgent ... Send me the full code
servlet - JSP-Servlet
servlet  How to convert multiple servlets into a single servlet,without increasing number of html files
JAVA SERVLET - JSP-Servlet
JAVA SERVLET Log   Hi, A servlet file which create the log files ,then writing values to the list & log, we should have a thousand separator and no decimal values. This means instead of writing 986300.0 in the Log file
servlet and jsp - JSP-Servlet
servlet and jsp  Hi friend, please show one sample program, how to connect jsp and servlet using backend a ms-access.  Hi friend,<%@ page language="java" import="java.sql.*,java.util.*,java.text.*"
servlet and jsp - JSP-Servlet
servlet and jsp  Hello folks, I am very new JDBC. I am doing a project on java messaging service on the part of the project we are using JDBC. In my...   write in the jsp form action="path of servlet" and wirite
servlet - JSP-Servlet
data on a servlet. //myServlet.java// here do something like this-- String
servlet-jsp - Java Beginners
servlet-jsp  hello sir i want the total code to create a website by taking input as vehicle number and model of it from user and with that fetch the details from database by checking the vehicle number and model and shud display
Compiling a Servlet - JSP-Servlet
Compiling a Servlet  Respected sir, I just want to know how to compile a servlet coding? I need it in a sequential way so that I can understand it at the very first time as I am new to this technology
servlet - JSP-Servlet
servlet  I m new in servelet i need help to know abt servlet how to install tomcat, how to run tomcat, how to make servlet program, how run... and then develop simple applications. You can learn servlet at http
on servlet - JSP-Servlet
on servlet deployment  What we'll get on servlet deployment
servlet - JSP-Servlet
servlet navigation problem  Hi, i am facing problem in Servlet navigation
servlet and jsp - JSP-Servlet
servlet and jsp  can any one give me jsp-servlet related project-its urgent- 1-chat application 2-bug tracking system 3-online shopping 4-online...://www.roseindia.net/jsp/bank.shtml Thanks
Servlet and Jsp - JDBC
Servlet and Jsp  Sir I am getting Nullpointer exception in for(itr=itr=data.iterator();itr.hasNext();),of the below program. http://www.roseindia.net/mysql/select-box.shtml
Logout Servlet - JSP-Servlet
Logout Servlet  Hello. I am trying to write servlet that will log user out when the user clicks the log out button or link. Please help
Servlet - JSP-Servlet
Servlet  I have a html signup.html page containing name, id ,password and confirm password paremeters, and in the servlet called SignUp.java i... signup javacode.SignUp signup /jsp/SignUp
jsp/servlet - JSP-Servlet
jsp/servlet  Hello friends ! I want to create columns in a table at run time everyday. I am using mysql database.how should I do it? thanks in advance  Hi friend, Plz explain your problem in details to solve
servlet - JSP-Servlet
*; import javax.servlet.*; import javax.servlet.http.*; public class Servlet extends...(); RequestDispatcher dispatcher = context.getRequestDispatcher("/jsp/form.jsp... FormServlet /FormServlet Servlet Servlet Servlet /Servlet Thanks
servlet - JSP-Servlet
servlet  How can i use javascript in servlet page to print alert message  Hi friend, printAlert.js function printAlert...(); } } For more information on Servlet visit to : http://www.roseindia.net
servlet/jsp - JSP-Servlet
servlet/jsp  Thanks for ur feedback! But this program shows an error showing package.org.apache.commons.fileupload.servlet does not exists package.org.apache.commons.fileupload.disk does not exists
servlet - JSP-Servlet
servlet  hi sir,plz provide what is a servlet ,how to run the servlet and what r the good books for understanding servlets,plz provide me  Hi Friend, Please visit the following link: http://www.roseindia.net
Servlet - JSP-Servlet
Servlet  Hi, Can Servlet have instance variables.If yes please give an example. Thanks, Poonam
Variables in a Servlet - JSP-Servlet
Variables in a Servlet   Hi, I'm using some variables in a servlet1 (which i get from a jsp, like "String x = request.getParameter("xyz");"). the servlet response is a jsp page which after taking some more parameters gets
servlet - JSP-Servlet
servlet  1.how can i run servlet program without creating html and xml program on tomcat 5.0? 2.how to use weblogic for servlet
servlet - JSP-Servlet
class Servlet extends HttpServlet { public void doPost(HttpServletRequest
servlet - JSP-Servlet
content and write a servlet program to validate the user.  Hi Friend...*; import javax.servlet.http.*; public class Servlet extends HttpServlet { public... { response.sendRedirect("./jsp/login.html"); } } catch(Exception e) {} } } Thanks
deployment of servlet - JSP-Servlet
deployment of servlet  i have problem deploying theservlet , im posting the code please help me servlet class import javax.servlet.*; import... Select beer charcteristics light amber brown servlet
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.