request.getParameter("uname")和session.getAttribute("uname")有什么区别

前者是从request取数据,通俗说就是从浏览器取数据
后者是从session取数据,也就是从服务器取自己的数据
package edu.njupt; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Objects; @WebServlet("/MyWeb") public class ServletDemo03 extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=utf-8"); HttpSession session = req.getSession(); User inputUser = new User(); PrintWriter out = resp.getWriter(); String uname = req.getParameter("uname"); String uQQ = req.getParameter("uQQ"); String uemail=req.getParameter("uemail"); String uaddress=req.getParameter("uaddress"); String unumber=req.getParameter("unumber"); String usex=req.getParameter("usex"); String uid=req.getParameter("uid"); String checkcode = req.getParameter("check-code"); String cb = req.getParameter("cb"); String CC = (String) req.getSession().getAttribute("checkCode"); // inputUser.setname(req.getParameter("name")); // inputUser.setUserQQ(req.getParameter("QQ")); // inputUser.setUseremail(req.getParameter("email")); // inputUser.setUseraddress(req.getParameter("address")); // inputUser.setUsernumber(req.getParameter("number")); // inputUser.setUsersex(req.getParameter("sex")); // inputUser.setUserid(req.getParameter("id")); System.out.println(uname); System.out.println(uQQ); System.out.println(uemail); System.out.println(uaddress); System.out.println(unumber); System.out.println(usex); System.out.println(uid); System.out.println(checkcode); System.out.println(cb); String[] cbs = req.getParameterValues("cb"); System.out.println(Arrays.toString(cbs)); if (Objects.equals(checkcode,CC)) { // User selectUser = UserDAO.getAUser(inputUser); if (uname !=null&&uQQ !=null&&uemail !=null&&uaddress !=null&&unumber !=null&&usex !=null&&uid !=null) { System.out.println("登陆成功"); // session.setAttribute("information", selectUser); // ArrayList userlist = UserDAO.getAllUser(); // session.setAttribute("userlist", userlist); req.getRequestDispatcher("/Suc").forward(req, resp); } else { System.out.println("登陆失败"); req.getRequestDispatcher("/Fail").forward(req, resp); } } else { System.out.println("验证码错误"); req.getRequestDispatcher("/CCW").forward(req, resp); } } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } }
02-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值