This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes upload a file in the server using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "upload a file in the server using jsp" Watch "upload a file in the server using jsp" New topic

upload a file in the server using jsp

rajashree loganayagi

Joined: Apr 12, 2011
Posts: 20
I have Html page which gets the information from user for the following fields: Serverurl, Username,Password,File to be uploaded.Once i click the submit button i need to upload that file to that server.

i have the following code to do the upload:

public class FileUploadServletLogic extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();
try {
ResourceBundle rb = ResourceBundle.getBundle("com.temenos.t24browser.upload.sftpproperties");
if (containsOnlyNumbers(TOTAL_MULTI_SERVER.trim())) {
int num_tms = Integer.parseInt(TOTAL_MULTI_SERVER);
int flag = 0;
if (ServletFileUpload.isMultipartContent(request)) {
// out.println(request.getParameter("modeselect"));
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List fileItemsList = servletFileUpload.parseRequest(request);
Iterator it = fileItemsList.iterator();
// while (it.hasNext()) {
FileItem fileItemTemp = (FileItem);
FileItem ft2 = (FileItem);
String value = ft2.getString();

if (!fileItemTemp.isFormField()) {

String fileName = fileItemTemp.getName();
fileName = FilenameUtils.getName(fileName);
String baseName = FilenameUtils.getBaseName(fileName);
String extension = FilenameUtils.getExtension(fileName);
File fileurl = File.createTempFile(baseName, extension);
for (int i = 1; i <= num_tms; i++)
String FTP_URL;

String serverurl = request.getParameter("serverurl");
String userid = request.getParameter("userid");
String password = request.getParameter("password");
if(serverurl!= "" && userid != "" && password != "")
FTP_URL = serverurl;
FTP_USERNAME = userid;
FTP_PASSWORD = password;

FTP_URL = rb.getString((new StringBuilder()).append("FTP_URL[").append(i).append("]").toString());
FTP_USERNAME = rb.getString((new StringBuilder()).append("FTP_USERNAME[").append(i).append("]").toString());
FTP_PASSWORD = rb.getString((new StringBuilder()).append("FTP_PASSWORD[").append(i).append("]").toString());

I cant able to get the user's url,username,password..... can anyone help me to resolve this problem....
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60785

Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans

Joined: Jul 06, 2005
Posts: 1016
If you are doing a form upload using multi-part formdata, then calls to request.getParameter() will most likely fail.

Instead of calling request.getParameter(), you have to deal with them as FileItem objects as documented on this page
One way of doing it is to put the form field values into a map, and get them like that:

It is sorta covered in the JavaRanch Style Guide.
subject: upload a file in the server using jsp
Similar Threads
java mail:send data from text box and attachment file from jsp page to mail.
Submit multipart and form data
how to upload using html or javascript?
Eclipse fileupload no longer works
Image preview with upload