• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

upload a file in the server using jsp

 
rajashree loganayagi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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....
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Stefan Evans
Bartender
Posts: 1755
10
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic