• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

upload a file in the server using jsp

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic