aspose file tools*
The moose likes JSP and the fly likes import  an file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "import  an file" Watch "import  an file" New topic
Author

import an file

anvi kon
Ranch Hand

Joined: Jan 08, 2010
Posts: 133
How would I import an excel or Any file from the C: directory on a jsp page?

Is it possible?

Can anyone give some examples?


Thanks.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Your JSP will result in an HTML page. Is the stuff you want to import also JSP or HTML?

In the case of an Excel spread sheet, of course the answer is 'no'. If you want to have your application serve multimedia content, like images, Excel spreadsheets, powerpoint presentations, music files, etc., then you need a separate servlet for this purpose. There is an article on the ServletsFaq page which talks about creating an image servlet for just such a purpose. You can see the article here: http://faq.javaranch.com/java/ImageServlet.

If I've misunderstood your request, please excuse me.
anvi kon
Ranch Hand

Joined: Jan 08, 2010
Posts: 133
I want to import a file which contains all data not a image on a jsp page.

Thanks
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
anvi kon wrote:I want to import a file which contains all data not a image on a jsp page.

Thanks
What does this data look like? What format is it?
When you import into a JSP page, the content must be appropriate for the JSP page (HTML, text, etc.).
You can't just import an Excel spreadsheet.

Try providing more than a one line answer
anvi kon
Ranch Hand

Joined: Jan 08, 2010
Posts: 133
The data can be a text or.xls.

Is it possible to import an excel data on the jsp page?


Can you please provide some examples?


thanks
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
I can't give you an example of importing an Excel spreadsheet into your JSP page.
You can include other JSP/HTML files using various flavors of the include tags. The best approach is to use the <c:import...> tag of the JSTL (Java Standard Tag Library).
However, the JSP has an include tag as well, <jsp:include ...> if you really don't want to use JSTL.
Note that the book: Core Servlets and JavaServer Pages has a chapter on including files in JSP pages. The book's chapters are available for free download from the book's website: http://pdf.coreservlets.com
anvi kon
Ranch Hand

Joined: Jan 08, 2010
Posts: 133
I want to know the approach to import a file.

Suppose If I click the import button should I upload the file and read it and extract the data on jsp page.


I need you'r suggestions

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

anvi kon wrote:I want to know the approach to import a file.
You have never explained what you mean by this. What is the purpose of "importing" the file -- whatever you intend for that to mean? What is the outcome you are after?

You can't just plunk an Excel file in the middle of HTML and expect anything good to happen, so you need to put in the effort to explain what you want to do. Otherwise, you are just wasting your time and other people's time.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
anvi kon
Ranch Hand

Joined: Jan 08, 2010
Posts: 133
Hi ALL,


I would like to hava a button import on the web Page. If the user clicks the button import, he should be able to open the file (text/.xsl) and import all the data from (text/xsl) on the jsp page.

What would be the best way to do it?


Please help me with some suggestions or examples.


Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

and import all the data from (text/xsl) on the jsp page.

Again -- what do you mean by this? As I said, you can't just embed the Excel file into HTML. Do you want it to replace the page? Do you want it to download to the user's system? Do you want it to open up in Excel? Or do you want to just import the data, and show it in an HTML table?

TellTheDetails!

Just saying "I want to import the file" doesn't tell us what you mean by that.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
First of all, text and XLS data formats are completely different. In general, they cannot be treated the same way.

When the user clicks the import button, where will the file be located which they wish to import? Will it be on their local computer?

If so, then the first part of your problem is to allow the user to upload the file to the server. See the FileUpload library from Apache Commons for help in doing this: http://commons.apache.org/fileupload/using.html.

If you then want to display this file on a web page, the way to do that depends on the format of the file. How you display a text file is different from how you would display an Excel spread sheet file (both are different from how you would display an Image or a music file, etc.).

You simply cannot create a page which can just display any type of file. You need to decide what types you wish to deal with, then implement the code necessary for each type. For example, you cannot simply serve the data from an Excel file in the middle of an HTML page. It will just look like garbage. There are ways, however, to serve non-HTML content. See the Image Servlet example in the ServletsFaq page for one way.
anvi kon
Ranch Hand

Joined: Jan 08, 2010
Posts: 133
Thanks for you'r reply.


I would like to read the .xls file from that location and import the data, and show it in an HTML table.


Is it clear now? Sorry for the confusion.


Thanks
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
anvi kon wrote:Thanks for you'r reply.

I want to import the file from the location on the jsp page(HTML format).



Perhaps there's a language barrier here. What you wrote makes no sense to me at all. There is no file in the middle of a JSP page to import. Perhaps what you mean by "import" is different from what I am used to?

Given that you continue to supply the same meaningless one-line answers, I'm beginning to wonder whether you actually want any help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Please do not ninja-edit your posts after someone has responded. It makes the thread difficult to follow.

Now that we finally know what you mean:
  • Extracting the data from the spreadsheet is not something that should be done in the JSP.
  • Under control of the page controller, delegate extracting the data from the spradsheet to a Java class created for that purpose. The more flexible and resuable this class is, the better.
  • The POI project might be useful for the data extraction.
  • The extracted data should be in a normal Java collection, or even arrays.
  • Pass the data to the JSP as a scoped variable and forward to the JSP.
  • In the JSP, use the JSTL and EL to format the HTML table.

  •  
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: import an file