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 没导入,请问怎么导入呢
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();
}