标签:年龄 font user zha 另一个 jsp页面 word res hang
//一.在servlet中的步骤
//1.获取参数,在地址栏输入
String username = request.getParameter("username");
String password = request.getParameter("password");
String realname = "张三";
String gender = "男";
int age = 22;
//2.判读,进行跳转
if ("zhangsan".equals(username) && "123456".equals(password)) {
//在request作用域中设置key-value
request.setAttribute("username", username);
request.setAttribute("realname", realname);
request.setAttribute("gender", gender);
request.setAttribute("age", age);
//然后使用请求转发到另一个页面(index.jsp)去取这个值(value)
request.getRequestDispatcher("index.jsp").forward(request, response);
}
}
//二.在jsp中的设置
欢迎<%=request.getAttribute("username")回来!
真实姓名:<%=request.getAttribute("realname") %>
性别:<%=request.getAttribute("gender")%>
年龄:<%=request.getAttribute("age") %>
存在缺点:数据多了,存储麻烦
标签:年龄 font user zha 另一个 jsp页面 word res hang
原文地址:https://www.cnblogs.com/su-chu-zhi-151/p/11221832.html