Java Web笔记 - 错误处理参数回显的实现方法

发布于 2011-11-12 | 更新于 2020-09-20

1、使用转发实现:

req.setAttribute(“username”, username);
req.setAttribute(“authority”, authority);
RequestDispatcher rd = req.getRequestDispatcher(“login.jsp”);
rd.forward(req, resp);

2、使用重定向实现:

重定向只能传回一个URL,然后客户端只能使用giaURL重新发送请求,所以只能把参数附加在URL中进行传递。

resp.sendRedirect(“login.jsp?username=”+username+"&authority="authority);

3、页面的回显处理:

输入框的回显:

username:<input type=“text” id=“username” name=“username” value=“<%= null == request.getAttribute(“username”)? “”:request.getAttribute(“username”) %>”/>

下拉框的回显:

本文作者: arthinking

本文链接: https://www.itzhai.comjava-web-notes-error-handling-implementation-of-echo-parameters.html

版权声明: 版权归作者所有,未经许可不得转载,侵权必究!联系作者请加公众号。

×
IT宅

关注公众号及时获取网站内容更新。