我是动态 web 项目概念的新手。我做了以下两个 JSP 和一个 java 类作为刚刚开始的实验。以下是我的代码
用户.java
package com;
public class User {
private String name;
private int Id;
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
索引.jsp
<
%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
</head>
<body>
<form action="First.jsp">
name<input type="text" name="name" />
id<input type="text" name="Id" />
<input type="submit" value="SUBMIT" />
<jsp:useBean id="user" class="com.User" />
<jsp:setProperty name="user" property="*"/>
</form>
</body>
</html>
又是 First.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Hello</title>
</head>
<body>
<jsp:useBean id="user" class="com.User" />
user is :<%= user.getName() %><BR>
Id is :<%= user.getId() %><BR>
</body>
</html>
但它向我显示两个值都为空。我知道它非常简单的程序。但我没有正确理解这个概念
谢谢