【发布时间】:2014-07-11 11:01:40
【问题描述】:
我已经使用 JSP、beans 和 JDBC (MVC) 制作了一个注册表
在我的 servlet 中,我有以下代码..
if ("editRegister".equalsIgnoreCase(action)) {
StudentBean user = new StudentBean();
user.setName(Name);
user.setStudID(ID);
user.setCourse(Course);
user.setEmail(Email);
db.addRecord(Name, ID, Name, Email);
set the result into the attribute
request.setAttribute("StudentBean", user);
RequestDispatcher rd;
rd = getServletContext().getRequestDispatcher("/DisplayRegistry.jsp");
rd = getServletContext().getRequestDispatcher("/UpdateRegistry.jsp");
rd.forward(request, response);
基本上,我想将我的 requestDispatcher 发送到两个 jsp 页面,以便我可以在表单内显示另一个具有预定义值的表单。
例如
<jsp:useBean id="StudentBean" scope="request" class="ict.bean.StudentBean"/>
<% String email = StudentBean.getEmail() != null ? StudentBean.getEmail() : ""; %>
<form method="get" action="updateregistry">
<input type="text" name="email" maxlength="10" size="15" value="<%=email%>">
</form>
但是,问题是它显示 null 而不是 value,因为 requestDispatcher 只发送到一个路径。
【问题讨论】:
-
所以你想将两个视图转发给客户端。这没有任何意义。拨打
rd.forward(request, response);后不要拨打PrintWriter out = response.getWriter(); -
你想要达到的目标。再解释一下。
-
我有一个注册表单,它接受用户的输入并将其保存到数据库中。现在我想创建另一个可以更新以前的注册表单的表单,并且我希望以前的输入显示在文本字段中,以便用户可以更新
-
但它在输入字段中显示 null 而不是以前输入中的值
标签: java jsp servlets javabeans