How can I open an excel from a java jsp javascript?
I have a JSP, with a link: Open EXCEL file
. If you click on it, it should open the something.xls
with microsoft excel .
I tried it with the <a>
tag, but it doesn't work:
<a href="./something.xls" target="_blank">
Open EXCEL file
</a>
Could anyone give me some useful code, and help, how to open an xls by excel from jsp? Thank you!
NO simply,you cannot open like that,Since the files can be open/downloaded by browser,and HTML/Javascript cannot have access to those system level programms.
You might need some Applet/Flash codes,which have access to communicate with system level.
It sounds like you are trying to get Excel to open on your client machine. As long as that is really what you are trying to do - then you would need to send the appropropriate mime type in your response header to let the browser know they type of they file is 'xls'.
See this question: Setting mime type for excel document
That also means that you would have to have a servlet manage the download rather than simply using an HTML anchor tag directly pointing to the file on the server. Or, you would need to configure your server to send the appropriate mime type whenever a spreadsheet file is being sent to the browser.
Try putting this in your web.xml file:
<!-- Set Excel mime-mapping so spreadsheets open properly instead of being sent as an octet/stream -->
<!-- If this is not done, the user may be prompted to save the file, or it may open as garbage text in the browser -->
<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>
(credit: http://wiki.metawerx.net/wiki/Web.xml.MimeMapping)
链接地址: http://www.djcxy.com/p/46844.html