Problem Description: 1. Front page JSP pages through. Pass the Chinese parameter, the action receives the garbled 2. When downloading files, Chinese files cannot be displayed.
Solution: 1. Check the information on the Internet through the JSP page UrlEncode can be resolved, but I transfer English parameters, bypassing the problem
2. In the beginning did not understand the meaning of ${} in Struts.xml, leading to the filename has not been obtained. In fact, this is struts automatically load the values in the stack, because I passed the id,filename, there is definitely no value. Later in the SetID method, add a value to the filename, the method may be a little strange, but the effect is achieved.
3. Download file name into Chinese, there is a lot of information on the Internet, through the setup charset=iso8859-1 successfully resolved.
Code:
Struts.xml
<action name= "downloadaction" class= "com.dcj.action.downloadAction" >
<result type= "Stream" >
<param name= "ContentType" >application/octet-stream;charset=ISO8859-1</param>
<param name= " InputName ">inputStream</param>
<param name=" contentdisposition ">attachment;filename=" ${ Docfilename} "</param>
<param name=" buffersize ">4096</param>
</result>
</ Action>
Action
public void SetId (String id) { this.id = ID; doc d = (doc) (Docserviceinter.findbyid (Doc.class, Integer.parseint (ID)); docfilename = D.getfilename (); }
Public String getdocfilename () throws unsupportedencodingexception { servletactionconte Xt.getresponse (). SetHeader ("CharSet", "iso8859-1"); Return New String (Docfilename.getbytes (), "iso8859-1"); }
Public InputStream getInputStream () {return servletactioncontext.getservletcontext (). getresource Asstream ("/upload/" +docfilename); }