【发布时间】:2014-02-05 16:41:14
【问题描述】:
下载 NetBeans 项目here。文件 -> 下载
使用JSTL 1.2 我试图让我的网络应用程序记住我的输入,然后在提交表单后将其放入输入框中,但由于某种原因它不记得了。我只有 1 个.java 类和.jsp 文件。
PersonController.java
package controller;
public class PersonController {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="controller.PersonController" %>
<jsp:useBean id="personController" class="controller.PersonController" scope="session"/>
<jsp:setProperty name="personController" property="name" param="name"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>PersonController</title>
</head>
<body>
<form method="post" action="index.jsp">
<input name="name" maxlength="30" type="text" id="name" value="<c:out value="${personController.name}"/>"><br/>
<input type="submit" name="button" value="Remember my name">
</form>
</body>
</html>
错误
HTTP 状态 500 - /index.jsp (line: 4, column: 0) useBean 类属性 controller.PersonController 的值无效。
如果它没有显示错误 #1,那么它不会在发布之前的输入后填充输入字段
name。
【问题讨论】: