servlet/jsp

servlet/jsp

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 Tutorials/Questions & Answers:
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
Advertisements
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
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-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
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
What is the difference between JSF, Servlet and JSP?
What is the difference between JSF, Servlet and JSP?  What is the difference between JSF, Servlet and JSP
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
How to pass an arraylist from servlet to jsp?
How to pass an arraylist from servlet to jsp?  Hello, Can anyone please tell me how to pass an arraylist from servlet to jsp? I have two arraylist... servlet to jsp? Thanks in advance
Difference Between Servlet and JSP
Difference Between Servlet and JSP In this section we will describe the Servlet and JSP. We will compare the both technologies. We will discuss the differences between Servlet and JSP. Servlet Servlet is a Java class that is usually
Servlet & Jsp - Java Interview Questions
Servlet & Jsp  how to forward or redirect the client request from servlet to jsp? how a thread or request pass from one servlet prog to one jsp prog? is it possible of communicating from servlet to jsp prog? please explain
Servlet & Jsp - Java Interview Questions
Servlet & Jsp   is it possible of communicating from SERVLET to JSP... servlet to jsp. Servlet2.java: import java.io.*; import javax.servlet...."))){ String jsp = "./jsp/loginSuccess.jsp"; RequestDispatcher dispatcher
JSP with java/servlet - JSP-Servlet
(java bean or servlet) to fecth the database. Jsp would get the data from.../servlet-jsp-data-list.shtml Hope that it will be helpful for you. Thanks...JSP with java/servlet  Thanks Deepak for your answere to my previous
Crop image Using JQuery, servlet or JSP.
Crop image Using JQuery, servlet or JSP.  Hi sir I need the code of Cropping image using JQuery with the help of servlet or JSP. I need both the code Client side as well as of server side. Please Help me
How to pass multiple values from a servlet to JSP?
How to pass multiple values from a servlet to JSP?  hi, I want to pass multiple values form a servlet to JSP. Hw do i do that? I am able to send one value at a time without any prb, but I am unable to carry multiple (from two
How to carry multiple values from a Servlet to a JSP?
How to carry multiple values from a Servlet to a JSP?  By using the below code I am able to carry the username to a JSP (single value... needs to be carried from my servlet to a JSP. How do I do
Servlet-JSP population - JSP-Servlet
Servlet-JSP population  Hi, I got my code worked. now I have another task. My jsp page on submit gets redirected to another servlet update cart... with textfields also. how the loop in the servlet should go to check all the boxes
Java servlet with jsp on sql server
Java servlet with jsp on sql server  How to delete a user by an admin with check box in Java Servlet with jsp on Sql Server?   Here is a jsp example that can delete the multiple record from the database by selecting
Servlet-JSP population - JSP-Servlet
Servlet-JSP population  Hi, this is regarding my previous question... and display in the next page. I changed my servlet code something like this but i find some problem retrieving the values from the jsp page. As my cart in jsp
Servlet - JSP Programming - JSP-Servlet
Servlet - JSP Programming  Hi, I'm writing a jsp page as shown... to cart or checkout). I'm programming in a servlet getting the input parameters... servlet code is also pasted below. please let me know how to solve
Servlet-JSP population - JSP-Servlet
Servlet-JSP population  In refernce to this Question http://www.roseindia.net/answers/viewanswers/9843.html I reduced my servlet code and JSP... in my jsp page my code is working fine. If I dont check any of the item in my
Servlet-JSP population - JSP-Servlet
Servlet-JSP population  Hi I have a login page which accepts inputs and take to a servlet, servlet makes a jdbc connection to oracle server... in I redirect to a JSP page which populates a list of items available
Servlet-JSP Mapping - JSP-Servlet
Servlet-JSP Mapping  Dear Sir, My Query were: How I use the issueData() in Jsp which define in Servlet_Two.java. If any mistake in my code please...\.wlnotdelete\extract\myserver_ProjDemo_ProjDemo\jsp_servlet\__issue.java' failed
Servlet-JSP Mapping - JSP-Servlet
Servlet-JSP Mapping  Dear Sir, My Query were: How I use the issueData() in Jsp which define in Servlet_Two.java. If any mistake in my code please...\.wlnotdelete\extract\myserver_ProjDemo_ProjDemo\jsp_servlet\__issue.java' failed
Distribute Servlet or JSP on network - JSP-Servlet
Distribute Servlet or JSP on network  Sir Even after successfully deploying a servlet or JSP program on J2EE web server I am not been able..." For any more problem on Servlet and Jsp visit to : http://www.roseindia.net
Override any method in servlet or jsp - JSP-Servlet
Override any method in servlet or jsp   Hi Friend, Can we override any life cycle methods in servlet and jsp.  Hi Please click on this url: http://www.roseindia.net/jsp/simple-jsp-example
Diff ways to call a EJB from Servlet, JSP - Java Interview Questions
Diff ways to call a EJB from Servlet, JSP  How can I call EJB from Servlet or JSP
ArrayList from JSP to Servlet - JSP-Servlet
in a scriplet in a jsp page. how can i access the arraylist in a servlet which... should it be declared in jsp and in servlet. do i need to do any casting...://www.roseindia.net/jsp/servlet-jsp-data-list.shtml Hope that it will be helpful for you
which version of eclipse is used to execute Servlet or JSP
Servlet or JSP. previosuly i installed eclipse 3.1 .i am having j2se 5.0 with which i...which version of eclipse is used to execute Servlet or JSP  Hi Can... JSP or Servlets with the help of Eclipse.Another point is that when i installed
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
how do i upload a file by using servlet or jsp?
how do i upload a file by using servlet or jsp?  hi plz tell me the write java code
Fetching database field from servlet to jsp page ?
Fetching database field from servlet to jsp page ?  Hello Java... field. I wanted to pass some of the database field from servlet to jsp... (i am opening my database in servlet init() method ) how to pass rs.getString(8
how to connect the database using hibernet through servlet/jsp through form
how to connect the database using hibernet through servlet/jsp through form  plz give me the reply   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/jsf/myfacesspring
how to store data in other table using servlet and jsp
how to store data in other table using servlet and jsp  pls can anyone tell how to store data in other table using servlet and jsp and want to display that data too.and the data in first table must be same.pls help
How to display Jfreechart from servlet in jsp web page at specified location
How to display Jfreechart from servlet in jsp web page at specified... in Servlet which is in image format.plz sir give me the code to display this chart in jsp web page . Thank you very much Sir
How to get the data from the database using Servlet or JSP program
How to get the data from the database using Servlet or JSP program  ... by using servlet or jsp program by typing the output as like this below.... Actual problem is that i have a simple program in jsp in the sense to get data
Capturing JSP Content Within My Strut Action Servlet - JSP-Servlet
Capturing JSP Content Within My Strut Action Servlet  My end goal is to be able to grab the content from the JSP from within the calling servlet... with a buffered output. * You can use this to forward or include a Servlet or JSP page
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
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
Java Servlet - JSP-Servlet
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  In the process of login validation. i'm entering the username correct and pass wrong. when using response.sendRedirect() a new req... help me with coding ? i'm just a beginner with JSP and sServlets
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

Ads