是一个非常简单的查询、删除、和修改的ejb例子,在ejb组件中有4个类文件:UserHome.class(Home interface) User.class (Remote interface) UserEJB.class(Bean class)还有一个LoginPassword.class(验证口令用的)
在web组件中有1个class文件2个html文件和6个jsp文件,都写出来太多了,我想知道,这个异常可能是有什么原因引起的,可能会在什么文件中出错,我感觉是jsp文件,但jsp文件找不到什么毛病?
下面是我的web组件中的class文件
package user.javabean;
import user.ejb.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
import java.sql.*;
import javax.sql.*;public class UserData{
private String id=null;
private String password=null;
private String name=null;
UserHome userhome=null;
public UserData() throws SQLException{
try{ Context initial=new InitialContext();
Object objref=initial.lookup("ejb/UserEJB"); userhome=(UserHome)PortableRemoteObject.narrow(objref, UserHome.class);
}catch(Exception ex){
throw new SQLException(ex.toString());
}
}
public void updateUser() throws SQLException{
try{
User user=userhome.findByPrimaryKey(id);
user.setUserData(name,password);
}catch(Exception ex){
throw new SQLException("更改失败!");
}
}
public void insertUser() throws SQLException{
try{
User user=userhome.create(id,name);
password=user.getPassword();
}catch(DuplicateKeyException dupkeyex){
throw new SQLException("id:"+id+"已经存在");
}catch(CreateException ex){
throw new SQLException("id:"+id+"添加失败");
}catch(Exception ex){
}
}
public void deleteUser() throws SQLException{
try{
User user=userhome.findByPrimaryKey(id);
user.remove();
}catch(Exception ex){
throw new SQLException("删除失败!");
}
}
public boolean isMember() throws Exception{
try{
User user=userhome.findByPrimaryKey(id);
if(user.getPassword().equals(password)){
name=user.getName();
return true;
}
}catch(ObjectNotFoundException notfoundex){
return false;
}catch(Exception ex){
throw ex;
}
return false;
}
public void setId(String id){
this.id=id;
}
public String getId(){
return id;
}
public void setPassword(String password){
this.password=password;
}
public String getPassword(){
return password;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
}
在web组件中有1个class文件2个html文件和6个jsp文件,都写出来太多了,我想知道,这个异常可能是有什么原因引起的,可能会在什么文件中出错,我感觉是jsp文件,但jsp文件找不到什么毛病?
下面是我的web组件中的class文件
package user.javabean;
import user.ejb.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
import java.sql.*;
import javax.sql.*;public class UserData{
private String id=null;
private String password=null;
private String name=null;
UserHome userhome=null;
public UserData() throws SQLException{
try{ Context initial=new InitialContext();
Object objref=initial.lookup("ejb/UserEJB"); userhome=(UserHome)PortableRemoteObject.narrow(objref, UserHome.class);
}catch(Exception ex){
throw new SQLException(ex.toString());
}
}
public void updateUser() throws SQLException{
try{
User user=userhome.findByPrimaryKey(id);
user.setUserData(name,password);
}catch(Exception ex){
throw new SQLException("更改失败!");
}
}
public void insertUser() throws SQLException{
try{
User user=userhome.create(id,name);
password=user.getPassword();
}catch(DuplicateKeyException dupkeyex){
throw new SQLException("id:"+id+"已经存在");
}catch(CreateException ex){
throw new SQLException("id:"+id+"添加失败");
}catch(Exception ex){
}
}
public void deleteUser() throws SQLException{
try{
User user=userhome.findByPrimaryKey(id);
user.remove();
}catch(Exception ex){
throw new SQLException("删除失败!");
}
}
public boolean isMember() throws Exception{
try{
User user=userhome.findByPrimaryKey(id);
if(user.getPassword().equals(password)){
name=user.getName();
return true;
}
}catch(ObjectNotFoundException notfoundex){
return false;
}catch(Exception ex){
throw ex;
}
return false;
}
public void setId(String id){
this.id=id;
}
public String getId(){
return id;
}
public void setPassword(String password){
this.password=password;
}
public String getPassword(){
return password;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
}
解决方案 »
- 谁知道Hibernate根据映射文件生成数据库表(注意:Spring来管理Hibernate配置文件)
- 实际开发中的xml
- Struts2 & Spring2.5 & Hibernate的开发问题
- 请问各位:在Jcreator中,没有软件包org.apache.Struts.util.*,怎么办啊?
- NumberFormatException 错误
- 运行EJB客户端出现的问题.Exception in thread "main" java.lang.NoClassDefFoundError
- 对象的属性问题,请高手指点,谢谢
- 初用Spring,请教Session为什么为空?
- eclipse和myeclipse有什么联系和区别?
- jboss中部署ejb出现问题!请指点!!
- 怎么建一个J2EE环境?
- EJB的 Local Interface Access问题。
login.jsp:<%@ page
language="java" errorPage="userErr.jsp"
import="java.sql.*,
user.javabean.*"
contentType="text/html; charset=GB2312" %><jsp:useBean id="userTbl" scope="page" class="user.javabean.UserData">
<jsp:setProperty name="userTbl" property="id" param="id"/>
<jsp:setProperty name="userTbl" property="password" param="password"/>
</jsp:useBean>
<% if(!userTbl.isMember()) throw new Exception("你不是会员!");
%>
<html>
<head></head>
<body bgcolor=#cccccc>
<p> </p>
<p> </p>
<div align=center>
<b><font size=7>欢迎光临!</font></b></div>
</body>
</html>查询
query.jsp:<%@ page language="java" errorPage="userErr.jsp" import="java.sql.*, user.javabean.*" contentType="text/html,charset=GB2312"%>
<jsp:useBean id="userTbl" scope="page" class="user.javabean.UserData">
<jsp:setProperty name="userTbl" property="id" param="id"/>
<jsp:setProperty name="userTbl" property="password" param="password"/>
</jsp:useBean>
<%if(!userTbl.isMember()) throw new Exception("你不是会员!");
%>
<html>
<head></head>
<body bgcolor=#cccccc>
<p> </p>
<p> </p>
<div align=center>
<p><b>
<font size=7>查询会员资料</font></b></p>
<form name=querForm action=update.jsp>
<p><font size=4>账号:<%=userTbl.getId()%><input type="hidden" name="id" value='<%=userTbl.getId()%>'>
名字:<input type=text name=name maxlength=8 value='<%=userTbl.getName()%>'>
密码:<input type=text name=password maxlength=8 value='<%=userTbl.getPassword()%>'>
</font></p>
<p>
<input type=submit name=Submit value="更改">
<a href=index.html>回首页</a></p>
</form>
<p> </p>
</div>
</body>
</html>