package com.Leonardo;public class userBean { public String useName;
public int myID;
public userBean(){
myID = 1001;
useName = "zahnghz";
}
public String getname(int ID){
if(ID==this.myID)
return useName;
else
return new String("NO Such man");
}
public int getID(){
return myID;
}
public void setID(int InID){
myID = InID;
}
}
<%@ page language="java" contentType="text/html; charset=GBK"
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=GB18030">
<title>Insert title here</title>
</head>
<body>
<form method ="post" action ="userbean.jsp">
<input type = "text" size="10" name ="ID"><p>
<input type = submit value ="submit"
</form>
</body>
</html><%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@ page import="com.Leonardo.userBean"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>张莹 0908014115</title>
</head>
<body>
<jsp:useBean id="OurBean" scope="application" class="com.Leonardo.userBean" />
<h4>Using Bean</h4>
<%
String tempStr = request.getParameter("ID");
out.println("hello");
int userID = Integer.valueOf(tempStr).intValue();
%>
<%=userID%>
<%=OurBean.getname(userID)%>
ID:<jsp:getProperty name="OurBean" property="ID" />
</body>
</html>
提示的是userBean不可用,估计是userBean.java 没导入,请问怎么导入呢
public int myID;
public userBean(){
myID = 1001;
useName = "zahnghz";
}
public String getname(int ID){
if(ID==this.myID)
return useName;
else
return new String("NO Such man");
}
public int getID(){
return myID;
}
public void setID(int InID){
myID = InID;
}
}
<%@ page language="java" contentType="text/html; charset=GBK"
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=GB18030">
<title>Insert title here</title>
</head>
<body>
<form method ="post" action ="userbean.jsp">
<input type = "text" size="10" name ="ID"><p>
<input type = submit value ="submit"
</form>
</body>
</html><%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@ page import="com.Leonardo.userBean"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>张莹 0908014115</title>
</head>
<body>
<jsp:useBean id="OurBean" scope="application" class="com.Leonardo.userBean" />
<h4>Using Bean</h4>
<%
String tempStr = request.getParameter("ID");
out.println("hello");
int userID = Integer.valueOf(tempStr).intValue();
%>
<%=userID%>
<%=OurBean.getname(userID)%>
ID:<jsp:getProperty name="OurBean" property="ID" />
</body>
</html>
提示的是userBean不可用,估计是userBean.java 没导入,请问怎么导入呢
解决方案 »
- [救助]ant编译问题与使用ant生成findbugs报告
- jsp中useBean的scope问题
- apache2.2.3与tomcat6.0.2的整合配置
- 数据库中是 100.00,为什么得出的却是 100.0 呢?
- 用jsp往数据库里查数据,没有插入成功
- struts 中怎样用checkbox?
- 各位高手帮我看一看这是怎么会事?十分感谢!!!
- 我在看java书,但是例子中有两个包找不到,知道这是什么包,能下吗?
- 遭遇(Element type "......" must be declared)
- ejb在jboss上的问题......(在jboss+ejb有经验的朋友请教了!)
- 权限问题
- 用struts2实现年份的下拉列表
String tempStr = request.getParameter("ID");
out.println("hello");
int userID = Integer.valueOf(tempStr).intValue();
我猜测是没有导入那个usebean这个类
真实的错误是空指针?!那很可能是 tempStr == null;你试试看:System.out.println("tempStr: " + tempStr );
String tempStr = request.getParameter("ID");
if (tempStr != null) {
out.println("hello");
userID = Integer.valueOf(tempStr).intValue();
}