Copy Code code as follows:
Server side:
public void Doget (HttpServletRequest req, HttpServletResponse resp)
Throws Servletexception, ioexception{
Req.setcharacterencoding ("GBK");
Create a new Smartupload object
Smartupload su = new Smartupload ();
Su.initialize (This.getservletconfig (), REQ,RESP);
Set contentdisposition NULL to prevent the browser from automatically opening the file.
Ensure that you click on the link to download the file. If not set, the downloaded file name extension is
Doc, the browser will automatically open it in Word. When the extension is PDF,
The browser will be opened with Acrobat.
Su.setcontentdisposition (NULL);
Download files
try {
Su.downloadfile ("d://upload/" + "test.txt");
catch (Smartuploadexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Copy Code code as follows:
Client:
<script>
function GetFile () {
$.get ("<%=basepath%>loadfileservlet", "" ", function (data) {
alert (data);
});
}
</script>
<a href= "#" onclick= "GetFile ()" >getfile</a>
txt in Chinese content does not show, if through the hyperlink access to the server side, download no garbled
, Mark, look at it later.