<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<%
request.setCharacterEncoding("gb2312");
String username=request.getParameter("textfield1");
String password=request.getParameter("textfield2");
if(username.equals("aaa")&&password.equals("111"))
{response.setContentType("application/msword;charset=gb2312");
 out.println("好样的");
}
else
{ response.setContentType("application/msword;charset=gb2312");
  out.print("没戏");
}
%>
</body>
</html>
上面的代码是获取登陆界面的用户名和密码,在设置响应的头部,让结果以word文档的形式保存。当我登陆之后,跳转到此页面,保存此页面的结果,保存的文件类型怎么是JavaScript Source Code.jsp??这儿没用脚本语言啊?还有当把保存的结果用word打开时,只有“好样的”这一结果,当以文本打开时怎么还有html语言??

解决方案 »

  1.   

    因为你前面的内容没有clear()啊
      

  2.   

    楼上的意思是用response.clear(),清除运行之后的结果??
      

  3.   

    你要想只输出
    out.println("好样的");
    你就得清空前面的内容啊,。或者在代码中去掉那些html
      

  4.   

    这个不是问题的关键,我问的是通过此句setContentType("application/msword;charset=gb2312"),设置结果以word文档保存,保存的后缀名为什么不是doc???我把保存的结果用word打开只有“好样的”把保存的结果用文本打开时除了"好样的"还带有html语言?