希望大家帮我看看怎样改这个程序,谢谢!

snoopy123808 2006-07-30 09:28:28
我按书作了以下的三个文件
1:static.html文件代码是:
<html>
<body>
<form method=post action="jsp_include.jsp">
<table>
<tr>
<td>please input your name:</td></tr>
<tr><td>
<input type=text name=name>
</td></tr>
<tr><td>input you password:</td>
<td>
<input type=text name=password>
</td>
</tr>
<tr>
<td>
<input type=submit value=login>
</td>
</tr>
</table>
</body>
</html>
第二个:jsp_include.jsp 代码是:
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<body>
<%@ include file="static.html" %>
<a href="two.jsp">goto two--></a><br>
this examples show include works
<jsp:include page="two.jsp" flush="true">
<jsp:param name="a1" value="<%=request.getParameter("name")%>" />
<jsp:param name="a2" value="<%=request.getParameter("password")%>" />
</jsp:include>
</body>
</html>
第三个:two.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<br>
this is a1=<%=request.getParameter("a1")%>
<br>
this is a2=<%=request.getParameter("a2")%>
<br>
<% out.println("hello from two.jsp");%>
在ie中运行如下:
please input your name:

input you password:

this examples show include works 举例说明include的工作原理:
this is a1=null
this is a2=null
hello from two.jsp

input you password:

this examples show include works 举例说明include的工作原理:
this is a1=null
this is a2=null
hello from two.jsp

但当我从please input your name: 后面的文本框输入中文时this is a1=后面却显示乱码,这是为什么?
能不能让它也显示中文?
请各位高手给我解释一下,谢谢了

...全文
149 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiangbo520 2006-08-03
  • 打赏
  • 举报
回复
楼上的,我上次回的帖搞错了,应该是<%request.setCharacterEncoding="GB2312";%>在TOMCAT中只能对POST方式传送的数据有效,对GET方式是无效的
yilue 2006-08-03
  • 打赏
  • 举报
回复
楼上说的对,用<%request.setCharacterEncoding="GB2312";%>就可以了,你的那个“gb2312”只是解决了浏览器的显示编码,没有解决请求传递的编码,以后你估计还会遇到数据库的显示问题哦,好好学习!
mx1029 2006-08-03
  • 打赏
  • 举报
回复
编码全用utf-8
iwlk 2006-08-02
  • 打赏
  • 举报
回复
怎么又是乱码问题, 晕
xiangbo520 2006-08-02
  • 打赏
  • 举报
回复
楼上的,
<%request.setCharacterEncoding="GB2312";%>在TOMCAT中只能对GET方式传送的数据有效,对POST方式传送的表单数据是不起作用的
lanseliuying 2006-08-02
  • 打赏
  • 举报
回复
可以直接加入<%request.setCharacterEncoding="GB2312";%>
试试吧
xiariguji 2006-08-01
  • 打赏
  • 举报
回复
楼主刚学?
加个中文转化处理函数就可以了//
public String codeString(String s)
{
String str=s;
try {byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
return str;
}
catch(Exception e){return str;}
}
假如你的字段是String a;
可使用a=codeString(a);
这样就可以解决乱码问题.
记得给分哦

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧