当前位置: 代码迷 >> Java Web开发 >> javax.servlet.ServletException: Feature not implemented
  详细解决方案

javax.servlet.ServletException: Feature not implemented

热度:1062   发布时间:2007-01-04 23:27:47.0
javax.servlet.ServletException: Feature not implemented

我做二个页面,一个用于登录,一个用于注册,当用户不在数据库中现有的用户中,则跳转到注册页面.
有二个bean,一个是UserBean,有一个registerUser(),一个是LoginBean,有一个isExist(),用来判断是否存在该用户,运行时,系统提示
root cause javax.servlet.ServletException: Feature not implemented
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.register_jsp._jspService(register_jsp.java:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java
我想是不是我的系统有问题,但又不知在哪里?
我用的是JBuilder12和TOMCAT 5.5.17和MYSQL5.0
请指教,谢谢!

搜索更多相关主题的帖子: Feature  implemented  javax  servlet  not  

----------------解决方案--------------------------------------------------------
没出现过你这个错误!
不过你贴贴代码,大家也许可以帮帮你!
----------------解决方案--------------------------------------------------------
UserBean

package etrade;

import java.io.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;

public class UserBean implements Serializable {
static int num=0; //用户ID,每次新注册用户,自增1
private String id;
private String name;
private String password;
private DataSource ds=null;

public UserBean() {
}

public int getNum(){
return num;
}

public String getId(){
return id;
}

public void setId(String id){
this.id=id;
}


public String getName(){
return name;
}

public void setName(String name){
this.name=name;
}

public String getPassword(){
return password;
}

public void setPassword(String password){
this.password=password;
}


public Connection getConnection() throws SQLException{
return ds.getConnection();
}

/**
* 关闭连接对象
*/
protected void closeConnection(Connection conn){
if (conn!=null){
try{
conn.close();
conn=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}

/**
* 关闭Statement对象
*/
protected void closeStatement(Statement stmt){
if (stmt!=null){
try{
stmt.close();
stmt=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}
/**
* 关闭PreparedStatement对象
*/
protected void closePreparedStatement(PreparedStatement pstmt){
if (pstmt!=null){
try{
pstmt.close();
pstmt=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}
/**
* 关闭ResultSet对象
*/
protected void closeResultSet(ResultSet rs){
if (rs!=null){
try{
rs.close();
rs=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}

/*
*新用户注册
*/
public void registerUser() throws SQLException{
Connection conn=null;
PreparedStatement pstmt=null;
String sql=null;

try{
conn=getConnection();
sql=" insert into user values(?,?,?) ";
pstmt=conn.prepareStatement(sql) ;
pstmt.setInt(1,++num) ;
pstmt.setString(2,name);
pstmt.setString(3,password);
pstmt=conn.prepareStatement(sql) ;
pstmt.executeUpdate();
}finally{
closePreparedStatement(pstmt);
closeConnection(conn);
}
}

}


----------------解决方案--------------------------------------------------------
LoginBean

package etrade;

import java.io.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.util.Collection;

public class LoginBean implements Serializable {
protected UserBean user;
private DataSource ds=null;

public LoginBean() {
}

public LoginBean(UserBean user)throws NamingException{
this.user = user;
Context ctx = new InitialContext() ;
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/etrade") ;
}

/**
* 得到数据库连接
*/

public Connection getConnection() throws SQLException{
return ds.getConnection();
}

/**
* 关闭连接对象
*/
protected void closeConnection(Connection conn){
if (conn!=null){
try{
conn.close();
conn=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}

/**
* 关闭Statement对象
*/
protected void closeStatement(Statement stmt){
if (stmt!=null){
try{
stmt.close();
stmt=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}
/**
* 关闭PreparedStatement对象
*/
protected void closePreparedStatement(PreparedStatement pstmt){
if (pstmt!=null){
try{
pstmt.close();
pstmt=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}
/**
* 关闭ResultSet对象
*/
protected void closeResultSet(ResultSet rs){
if (rs!=null){
try{
rs.close();
rs=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}

public boolean isValidate() throws SQLException{
String name = user.getName() ;
String password = user.getPassword();
Connection conn=null;
ResultSet rs=null;
PreparedStatement pstmt=null;

try{
conn=getConnection();
String sql = "select id,password from user where name = ?";
pstmt=conn.prepareStatement(sql) ;
pstmt.setString(1,name);
rs=pstmt.executeQuery();
if ( rs.next() && rs.getString(2).trim().equals( password )){
user.setId(rs.getString(1)) ;
return true;
}else{
return false;
}
}finally{
closeResultSet(rs);
closePreparedStatement(pstmt);
closeConnection(conn);
}
}

/*
*判断该用户名是否存在
*/
public boolean isExist() throws SQLException{
String name = user.getName() ;
Connection conn=null;
ResultSet rs=null;
PreparedStatement pstmt=null;

try{
conn=getConnection();
String sql="select * from user where name=?";
pstmt=conn.prepareStatement(sql) ;
pstmt.setString(1,name);
rs=pstmt.executeQuery();
Collection cl=(Collection)rs.getArray(1) ;
if ( cl.size()<=0){
return true;
}else{
return false;
}
}finally{
closeResultSet(rs);
closePreparedStatement(pstmt);
closeConnection(conn);
}
}
}


----------------解决方案--------------------------------------------------------
register

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" >
<title>基于agent的电子交易方法与实现</title>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Microsoft Theme" content="none, default">
<meta name="Microsoft Border" content="none, default">
</head>

<body>
<p>&nbsp;</p>
<form name="form1" method="post" action="register.jsp">
<table width="400" border="1" align="center">
<tr>
<td colspan="5">电子市场</td>
</tr>
<tr>
<td width="24">&nbsp;</td>
<td width="85">&nbsp;</td>
<td colspan="2">&nbsp;</td>
<td width="57">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>用户名:</td>
<td colspan="2"><label>
<input name="name" type="text">
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>密码:</td>
<td colspan="2"><label>
<input name="password" type="password">
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label></label></td>
<td width="103"><label>
<div align="center">
<input type="submit" name="Submit" value="注册">
</div>
</label></td>
<td width="97"><label>
<div align="center">
<input type="submit" name="Submit2" value="取消">
</div>
</label></td>
<td>&nbsp;</td>
</tr>
</table>
</form>
<p>&nbsp;</p>
</body>

</html>


----------------解决方案--------------------------------------------------------
register.jsp

<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="etrade.LoginBean" %>
<%request.setCharacterEncoding("GB2312") ; %>

<jsp:useBean id="user" scope="session" class="etrade.UserBean" />
<jsp:setProperty name="user" property="*" />

<%
LoginBean lb=new LoginBean(user) ;
if (lb.isValidate() ){
%>
<jsp:forward page="etrade" />
<%
}else{
out.println("用户名或密码错误,请<a href=\"index\">重新登录</a>或<a href=\"register\">注册</a>") ;
}
%>


----------------解决方案--------------------------------------------------------
不好意思。我在判断是不存在特定的用户时可能用错方法了。

大家帮我看一下这个BEAN,我定义了一个静态变量static int num=0; //用户ID,每次新注册用户,自增1
,目的是为了在注册新用户时,记录用户的ID,
conn=getConnection();
sql=" insert into user values(?,?,?) ";
pstmt=conn.prepareStatement(sql) ;
pstmt.setInt(1,++num) ;
pstmt.setString(2,name);
pstmt.setString(3,password);
pstmt=conn.prepareStatement(sql) ;
pstmt.executeUpdate();
但我在pstmt.setInt(1,++num);时系统报错,说第一参数没有设置,不知我错在哪里?谢谢!

package etrade;

import java.io.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class UserBean implements Serializable {
static int num=0; //用户ID,每次新注册用户,自增1
private String id;
private String name;
private String password;
private DataSource ds=null;

public UserBean() throws NamingException{
Context ctx = new InitialContext() ;
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/etrade") ;
}

public int getNum(){
return num;
}

public String getId(){
return id;
}

public void setId(String id){
this.id=id;
}


public String getName(){
return name;
}

public void setName(String name){
this.name=name;
}

public String getPassword(){
return password;
}

public void setPassword(String password){
this.password=password;
}


public Connection getConnection() throws SQLException{
return ds.getConnection();
}

/**
* 关闭连接对象
*/
protected void closeConnection(Connection conn){
if (conn!=null){
try{
conn.close();
conn=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}

/**
* 关闭Statement对象
*/
protected void closeStatement(Statement stmt){
if (stmt!=null){
try{
stmt.close();
stmt=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}
/**
* 关闭PreparedStatement对象
*/
protected void closePreparedStatement(PreparedStatement pstmt){
if (pstmt!=null){
try{
pstmt.close();
pstmt=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}
/**
* 关闭ResultSet对象
*/
protected void closeResultSet(ResultSet rs){
if (rs!=null){
try{
rs.close();
rs=null;
}catch(SQLException ex){
ex.printStackTrace() ;
}
}
}

/*
*新用户注册
*/
public void registerUser() throws SQLException{
Connection conn=null;
PreparedStatement pstmt=null;
String sql=null;

try{
conn=getConnection();
sql=" insert into user values(?,?,?) ";
pstmt=conn.prepareStatement(sql) ;
pstmt.setInt(1,++num) ;
pstmt.setString(2,name);
pstmt.setString(3,password);
pstmt=conn.prepareStatement(sql) ;
pstmt.executeUpdate();
}finally{
closePreparedStatement(pstmt);
closeConnection(conn);
}
}

}


----------------解决方案--------------------------------------------------------
你的userbean范围是SESSION,并不是全局STATIC。
为什么不用自增列?
----------------解决方案--------------------------------------------------------
对呀,谢谢!
我看到一个例子,就是通过一个静态变量实现总数的统计的,就没想到利用数据库自身的功能,谢谢!非常感谢!
----------------解决方案--------------------------------------------------------
  相关解决方案