This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to display only text file in selection windiw  RSS feed

 
mayur bhishma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to upload the text file in specific location in my disk but when I open selection window it displays all type of files while it should display the files only having .txt extensions
I am writing the code below,

<%@page import="org.apache.commons.fileupload.*,java.util.*,java.io.*"%>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<%
// JSP to handle uploading


// Create a new file upload handler
DiskFileUpload upload = new DiskFileUpload();

// parse request
List items = upload.parseRequest(request);

// get uploaded file
FileItem file = (FileItem) items.get(0);
String source = file.getName();

// get target filename
FileItem name = (FileItem) items.get(1);
String target = name.getString();

File outfile = new File("D:\\Uploader Test\\" + target);
file.write(outfile);


out.println("Upload Is Successful!");


%>
<div align="middle">
<a href="index.html"> Back </a>
</div>
</body>
</html>

Please suggest possible options to achieve this
thanks in advance...
 
Paul Clapham
Sheriff
Posts: 22502
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks like file uploading code to me, all right. But your question was about a "selection window"? And something which is supposed to do something based on file extensions? None of the code you posted has anything to do with that -- did you post the wrong code by mistake?
 
mayur bhishma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi paul,
yes it is a file uploading code and there are no issues regarding selection window , the issue is it should display only text file for uploading where as window displays all files present in perticular directory.

thanks in advance
 
Paul Clapham
Sheriff
Posts: 22502
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um... Perhaps you mean that the browser should only allow the user to upload files with a .txt extension? Is that the window you're asking about?

If that's your question (and I'm only guessing that it might be) then no, you can't make it do that. You could easily make that code examine the uploaded file name and reject it if you didn't like it.
 
mayur bhishma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!