无为清净楼资源网 Design By www.qnjia.com
在jsp中,我们经常从数据库读取数据返回客户端,但我们常常在制作时出现乱码现象,所以我们可以用<%request.setCharacterEncoding("UTF-8");%>这个方法来保证中文的正确输出,下面举个例子吧,
我们要接住表单的值或者把数据库数据打印出来的之前,先把<%request.setCharacterEncoding("UTF-8");%>放在他们的前面,然后,表单的提交方式必须是post,即method="post",这样可以闭避免乱码了,请看下面:
复制代码 代码如下:
<%request.setCharacterEncoding("UTF-8");%>
<form action="" method="post">
姓名:<input type="text" name="name"/>
<br/>
性别:<input type="text" name="sex" />
<%
String name=requset.getParameter("name");
String sex=request.getParameter("sex");out.print(name);
out.print(sex);
%>
</form>

或者有时用户登陆时,我们需要在某一页用到用户名或者密码,我们可以用下面这种方法来记住,在其他页面可以随便调用,如:
复制代码 代码如下:
<form action="" method="post">
用户名:<input type="text" name="name"/>
<br/>
密码:<input type="password" name="password" />
<form/>
String name=requset.getParameter("name");
String password=request.getParameter("password");
application.setAttribute("names",name);
application.setAttribute("passwords",password);密码和用户名就这样被记住了,在其他也可以随便调用,如下
application.getAttribute(“names");
application.getAttribute("passwords");
<%
out.print(application.getAttribute(“names"));
out.print(application.getAttribute(“passwords")
%>

这样就会输出文本框的值
标签:
jsp,传值,乱码

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com