用Jsp输出Word,PDF等文件时进行的设置
response.setContentType( "application/pdf" ); // MIME type for pdf doc
response.setHeader("Content-Disposition","attachment;filename=output.pdf;");
Sets the Content-Type header. Content-Type identifies the MIME type of the response document and the character set encoding.
To set the Content-Type header, use the following code:
response.setContentType("text/html; charset=gbk");
The default MIME type is text/plain. Some common MIME types include:
HTML format (.htm or .html): text/html
Adobe Portable Document (pdf): application/pdf
Microsoft Word (.doc): application/msword
Microsoft Excel (.xls): application/msexcel
Microsoft Powerpoint (.ppt): application/ms-powerpoint
Realaudio (.rm, .ram): audio/x-pn-realaudio
Text format (.txt): text/txt
Zipped files (.zip): application/zip
相关文档:
1. ActionContext
在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话
(Session)的一些信息,甚至需要直接对JavaServlet
Http的请求(HttpServletRequest),响应(HttpServletResponse)操作.
我们需要在Action中取得request请求参数"username"的值: ......
3. <jsp:forward page="" />
它的底层部分是由RequestDispatcher来实现的,因此它带有RequestDispatcher.forward()方法的印记。
如果在之前有很多输出,前面的输出已使缓冲区满,将自动输出到客户端,那么该语句将不起作用,这一点应该特别注意。
另外要注意:它不能改变浏览器地址,刷新的话会导致重复提交
4. 修改HTTP ......
一.request对象
客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。
当request对象获取用户提交的汉字字符时,会产生乱码,由下面的方法可以解决:
Sting s2 = new String(s1.getBytes("iso8859-1"),"GB2312") ......
一 MVC设计模式的概念
MVC本来是存在于Desktop程序中的,M是指数据模型,V是指用户界面,C则是控制器。使用MVC的目的是将M和V的实现代码分离,从而使同一个程序可以使用不同的表现形式。比如一批统计数据你可以分别用柱状图、饼图来表示。C存在的目的则是确保M和V的同步,一旦M改变,V应该同步更新。& ......
学习jsp时,乱码也是一个很头痛的事。
1.在jsp文件开头加上<%@ page contentType="text/html; charset=GBK"%>
2.解决post方式提交内容的乱码:request.setCharcterEncoding("GBK");
3.解决url(get,超链接)方式乱码问题是配置servlet.xml.在<Connector>标签中添加一句URIEncoding="GBK" 或者 string ......