怪事了,是什么原因?
JSP程序中,如果把下面一段直接写到JSP源程序的头上,可以正确运行并显示中文,
然而,如果把这一段无论用静态包含<%@include file = "code.jsp"%>还是用动态包
含<jsp:include>都不对。注意,这时我把下面一段放入了code.jsp文件中。
请大家指教:
code.jsp源文件
<%@page pageEncoding="GB2312"%>
<%@page contentType="text/html; charset=gb2312"%>
<%request.setCharacterEncoding("GB2312");%>
JSP源文件:
<%@include file = "code.jsp"%> //此时运行结果显示是乱码,即不正确。
<%
String action = request.getParameter("ACTION");
String name = "";
String str = "";
if(action!=null && action.equals("SENT"))
{
name = request.getParameter("name");
str = request.getParameter("str");
}
%>
<html>
<head>
<title></title>
<Script language="JavaScript">
function Submit()
{
document.base.action = "?ACTION=SENT&str=传入的中文";
document.base.method = "POST";
document.base.submit();
}
</Script>
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="5">
<form name="base" method = "POST" target="_self">
<input type="text" name="name" value="" size="30">
<a href = "JavaScript:Submit()">提交</a>
</form>
<%
if(action!=null && action.equals("SENT"))
{
out.println("<br>你输入的字符为:"+name);
out.println("<br>你通过URL传入的字符为:"+str);
}
%>
</body>
</html>
我想问为什么直接加入就可以正常运行,而用包含的方法就不行呢?