无为清净楼资源网 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")
%>
这样就会输出文本框的值
我们要接住表单的值或者把数据库数据打印出来的之前,先把<%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
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《幸福工厂》无限报错解决方法
- 交错战线原始交易所推荐角色一览
- 战锤40K星际战士2战术职业介绍|战术职业技能效果一览
- 战锤40K星际战士2突击职业介绍|突击职业技能效果一览
- [妙音金曲]群星《悲情咖啡屋》(黑胶)2CD[DTS-WAV]
- 阿兰·达瓦卓玛《A-Lan阿兰唯美歌姬》2CD[DTS-WAV]
- 【小提琴】陈立新《思乡曲》2004[FLAC+CUE]
- 《战地》新作明年初大规模测试!EA已内部测试一年
- 《GTAOL》PC版时隔多年更新反作弊!小助手宣布跑路
- EA称AI是其业务核心!能提高开发效率、节约成本
- 卫华.1990-太阳升【BMG】【WAV+CUE】
- 呼吸乐队.1992-THEBREATHING【深飞】【WAV+CUE】
- 李玟.2008-1994-2008豪华典藏精选2CD【SONY】【WAV+CUE】
- 《张学友 再现歌神的光辉岁月 梦想成真 2CD》[WAV/分轨][1.2GB]
- 《海来阿木 高音测试王》[WAV+CUE][500MB]