<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>动态响应</title></head>
<body>
<center>
<p>动态响应contentType属性的案例</p>
<hr><br>
请选择你的保存的格式:
<form action="test30.jsp" method="post" name="form3">
<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" value="提交" name="sub">
</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>
我怎么都编译不出来,希望大家帮帮我,谢谢了!
刚才只听一个同事说什么变量值没有初始化,也没细说。我是按照书本上写的,难道书上错了。
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>动态响应</title></head>
<body>
<center>
<p>动态响应contentType属性的案例</p>
<hr><br>
请选择你的保存的格式:
<form action="test30.jsp" method="post" name="form3">
<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" value="提交" name="sub">
</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>
我怎么都编译不出来,希望大家帮帮我,谢谢了!
刚才只听一个同事说什么变量值没有初始化,也没细说。我是按照书本上写的,难道书上错了。
楼主截止到2008-06-19 09:00:21的汇总数据:
注册日期:2008-6-6
上次登录:2008-6-19
发帖数:1
结贴数:0
结贴率: 0.00%
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
如果你直接进这个页面request.getParameter("format"); 取不到值
在这句后面加上判断
if(docType!=null){
后面的所有代码
}
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>动态响应 </title> </head>
<body>
<center>
<p>动态响应contentType属性的案例 </p>
<hr> <br>
请选择你的保存的格式:
<form action="test30.jsp" method="post" name="form3">
<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" value="提交" name="sub">
</form>
</center>
<%
String docType=request.getParameter("format");
docType = (docType == null ? "" : docType);
if(docType.equals("text")){
docType="text/html";
}
else if(docType.equals("word")){
docType="application/msword";
}
else if(docType.equals("excel")){
docType="application/x-msexcel";
}
if(!docType.equals("")){
response.setContentType(docType);
}
%>
</body>
</html>
这跟<select>,<input>还是其他的form元素都没有关系
if("text".equals(docType)){
docType="text/html";
}...
......