aspose file tools*
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 Spring in Action this week in the Spring 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
Author

upload a file in the server using jsp

rajashree loganayagi
Greenhorn

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 {
response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();
try {
ResourceBundle rb = ResourceBundle.getBundle("com.temenos.t24browser.upload.sftpproperties");
String TOTAL_MULTI_SERVER = rb.getString("TOTAL_MULTI_SERVER");
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) it.next();
FileItem ft2 = (FileItem) it.next();
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);
fileItemTemp.write(fileurl);
for (int i = 1; i <= num_tms; i++)
{
String FTP_URL;
String FTP_USERNAME;
String FTP_PASSWORD;

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;
}

else
{
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
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

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
Bartender

Joined: Jul 06, 2005
Posts: 1018
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:

ie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: upload a file in the server using jsp