servlet中的数据传递

servlet中的数据传递
使用request的setAttribute()方法
传递方:
  request.setAttribute("str","用户名或者密码错误");
接收方:
String str = (String) request.getAttribute("str")
注:因为request.getAttribute()返回的是object对象,所以这里使用了类型转换接收
若要让servlet返回的数据中文显示不乱码需要设置
 
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("gbk");
 
posted @ 2021-08-09 10:39  七七负柒柒  阅读(133)  评论(0)    收藏  举报