JSP如何引用外部类?

cart55free99 2009-10-19 01:31:26
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>
...全文
190 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cart55free99 2009-11-05
  • 打赏
  • 举报
回复
我解决啦!不过这么久都没人回答, 应该再放jsp之前放好bean包,哈哈
cart55free99 2009-10-19
  • 打赏
  • 举报
回复
我就是想问含有内部类的bean包应该放在哪里?

24,918

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧