JSP如何引用外部类?
JSP如何引用外部类?我想把UserReg.jsp中的内容通过外部类引用 最后显示在UserShow中
外部类应该刚在哪里?
我的工程名叫做web 外部类User.java放在了bean包中 bean放在web下的src中 这样不行 ,那应该放在那里?
bean放在WebRoot下也不行
UserReg.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="GBK"%>
<!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="UserShow.jsp" method="post">
userName<input name="userName" type="text">
age<input name="age" type="text">
<input type="submit" value="SUBMIT">
</form>
</body>
</html>
接下来是要引用的外部类User.java
package bean;
public class User {
String userName;
int age;
public User(){
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Usershow.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="bean.User"%>
<!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>
<jsp:useBean id="obj" class="bean.User" scope="page" />
<jsp:setProperty name="obj" property="*" />
name:<%=obj.getUserName()%>
age:<%=obj.getAge()%>
</body>