日期:2014-05-17 浏览次数:20979 次
<%@ page contentType="text/html;charset=gbk" language="java" %>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=gbk" />
        <title>动态响应contentType属性</title>
        </head>
    <body>
        <center>
            <p>动态响应contentType属性的案例</p>
            <hr><br>
            请选择你的保存的格式:
            <form action="SetContentType.jsp" name="myForm" method="post">
                <select name="format" id="format" >
                    <option value="text" >文本文件</option>
                    <option value="word">word文件</option>
                    <option value="excel">Excel文件</option>
                    </select>
                <br><br>
                <input type="submit" name="save" value="保存">
                </form>
            </center>
        <%
            String docType = request.getParameter("format");
            if(docType.equals("text")) {
                docType = "text/html";
            } else if(docType.equals("word")) {
                    docType = "application/msword";
                } else if(docType.equals("excel")) {
                        docType = "application/x-msexcel";
                    }
            response.setContentType(docType);
        %>
        </body>
    </html>