用户表User
package bill.dbweb.db;public class User implements java.io.Serializable
{ private static final long serialVersionUID = 1L;
private String userId;
private String userName;
private String userPwd;
private String userQx;
public User()
{
}
public User(String userId)
{
this.userId = userId;
}
public User(String userId, String userName, String userPwd, String userQx)
{
this.userId = userId;
this.userName = userName;
this.userPwd = userPwd;
this.userQx = userQx;
}
public String getUserId()
{
return this.userId;
} public void setUserId(String userId)
{
this.userId = userId;
} public String getUserName()
{
return this.userName;
}
//后面代码略
}
UserDao的代码 接口
package bill.dbweb.db.dao;import bill.dbweb.db.*;
import java.util.*;public interface UserDao
{
public void insert(User user) throws Exception;
public void delect(User user) throws Exception;
public void update(User user) throws Exception;
public User querById(String Id ) throws Exception;
public User querUser( String UserName, String UserPasswd) throws Exception;
public List querAll() throws Exception;
public List queryByLike(String cond) throws Exception ;
}实现接口
package bill.dbweb.db.impl;import bill.dbweb.db.*;
import bill.dbweb.db.dao.*;import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;public class UserDaoImpl implements UserDao
{
private static final User User = null; public void insert(User user) throws Exception
{}
后面实现的各个方法 略
}现在的问题是:我怎么在JSP中实现这个接口
<%@ page language="java" pageEncoding="GB2312"%>
<%@ importbill.dbweb.db.*, importbill.dbweb.db.dao.* , importbill.dbweb.db.impl.UserDaoImpl%>
<html>
<head></head>
<body>
<%
UserDaoImpl UserDaoImpl= null;
String uname = request.getParameter("uname");
String password = request.getParameter("passwd");
UserDaoImpl = UserDaoImpl.querUser(uname, password);
if (null == UserDaoImpl)
{
response.sendRedirect("login.htm");
System.out.println("no such a user");
return;
}
else
{
}
catch (Exception e) {
response.sendRedirect("login.htm");
return;
} %>为什么它老是 UserDaoImpl UserDaoImpl= null; 报错?
UserDaoImpl cannot be resolved to a type
包也导进来了!怎么回事
package bill.dbweb.db;public class User implements java.io.Serializable
{ private static final long serialVersionUID = 1L;
private String userId;
private String userName;
private String userPwd;
private String userQx;
public User()
{
}
public User(String userId)
{
this.userId = userId;
}
public User(String userId, String userName, String userPwd, String userQx)
{
this.userId = userId;
this.userName = userName;
this.userPwd = userPwd;
this.userQx = userQx;
}
public String getUserId()
{
return this.userId;
} public void setUserId(String userId)
{
this.userId = userId;
} public String getUserName()
{
return this.userName;
}
//后面代码略
}
UserDao的代码 接口
package bill.dbweb.db.dao;import bill.dbweb.db.*;
import java.util.*;public interface UserDao
{
public void insert(User user) throws Exception;
public void delect(User user) throws Exception;
public void update(User user) throws Exception;
public User querById(String Id ) throws Exception;
public User querUser( String UserName, String UserPasswd) throws Exception;
public List querAll() throws Exception;
public List queryByLike(String cond) throws Exception ;
}实现接口
package bill.dbweb.db.impl;import bill.dbweb.db.*;
import bill.dbweb.db.dao.*;import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;public class UserDaoImpl implements UserDao
{
private static final User User = null; public void insert(User user) throws Exception
{}
后面实现的各个方法 略
}现在的问题是:我怎么在JSP中实现这个接口
<%@ page language="java" pageEncoding="GB2312"%>
<%@ importbill.dbweb.db.*, importbill.dbweb.db.dao.* , importbill.dbweb.db.impl.UserDaoImpl%>
<html>
<head></head>
<body>
<%
UserDaoImpl UserDaoImpl= null;
String uname = request.getParameter("uname");
String password = request.getParameter("passwd");
UserDaoImpl = UserDaoImpl.querUser(uname, password);
if (null == UserDaoImpl)
{
response.sendRedirect("login.htm");
System.out.println("no such a user");
return;
}
else
{
}
catch (Exception e) {
response.sendRedirect("login.htm");
return;
} %>为什么它老是 UserDaoImpl UserDaoImpl= null; 报错?
UserDaoImpl cannot be resolved to a type
包也导进来了!怎么回事
UserDaoImpl userDaoImpl !
String uname = request.getParameter("uname");
String password = request.getParameter("passwd");
UserDaoImpl = UserDaoImpl.querUser(uname, password); // UserDaoImpl.querUser返回的是user类型,你怎么这么写
基础知识不牢固,建议多看些资料
试下.
<%@ importbill.dbweb.db.*, importbill.dbweb.db.dao.* , importbill.dbweb.db.impl.UserDaoImpl%>
<html>
<head> </head>
<body>
<%!
UserDaoImpl UserDaoImpl= null;
String uname = request.getParameter("uname");
String password = request.getParameter("passwd");
UserDaoImpl = UserDaoImpl.querUser(uname, password);
if (null == UserDaoImpl)
{
response.sendRedirect("login.htm");
System.out.println("no such a user");
return;
}
else
{
}
catch (Exception e) {
response.sendRedirect("login.htm");
return;
} %> 这样试试,偶加了感叹号"<%!"
UserDaoImpl userDaoImpl= new UserDaoImpl();
String uname = request.getParameter("uname");
String password = request.getParameter("passwd");
UserDaoImpl = userDaoImpl.querUser(uname, password);
if (null == userDaoImpl)
{
response.sendRedirect("login.htm");
System.out.println("no such a user");
return;
}
else
{
}
catch (Exception e) {
response.sendRedirect("login.htm");
return;
} %> UserDaoImpl 这个定义时用userDaoImpl吧,不要和其同名,虽然也能编译通过,至于为啥,楼主自己想想吧
UserDaoImpl userDaoImpl = userDaoImpl.querUser(uname, password); 这样还可以少创建一个对象,呵呵。
UserDaoImpl MyUserDaoImpl=new UserDaoImpl() ;
String uname = request.getParameter("uname");
String password = request.getParameter("passwd");
User MyUser = MyUserDaoImpl.querUser(uname, password);
为什么还报错呢?UserDaoImpl cannot be resolved to a type 包我确实导入了
<%@ importbill.dbweb.db.*%>
<%@ importbill.dbweb.db.dao.*%>
<%@ importbill.dbweb.db.impl.UserDaoImpl%>
<%@ import bill.dbweb.db.dao.*%>
<%@ import bill.dbweb.db.impl.UserDaoImpl%>
import和导入的包名需要一个空格
这句隐藏的潜在问题可能被当前问题所掩盖了 ls之中也有所提到UserDaoImpl cannot be resolved to a type
<%@ importbill.dbweb.db.*, importbill.dbweb.db.dao.* , importbill.dbweb.db.impl.UserDaoImpl%>
看看这句导入包是不是格式等有问题导致UserDaoImple无法被解析为类型
String password = request.getParameter("passwd");
User MyUser=new UserDaoImpl.querUser(uname, password); ;
if (null == MyUser)
{
response.sendRedirect("login.htm");
System.out.println("no such a user");
return;
} } catch (Exception e) {
response.sendRedirect("login.htm");
return;
}
你这样导包试试
String uname = request.getParameter("uname");
String password = request.getParameter("passwd");
User MyUser=new UserDaoImpl.querUser(uname, password); ;
if (null == MyUser)
{ response.sendRedirect("login.htm");
System.out.println("no such a user");
return;
} } catch (Exception e) {
response.sendRedirect("login.htm");
return;
}
包导入的地方我改正
<%@ importbill.dbweb.db.*%>
<%@ importbill.dbweb.db.dao.*%>
<%@ importbill.dbweb.db.impl.UserDaoImpl%>
可是出现了一个警告Unknown tag (jsp:directive.importbill.dbweb.db.*)看来还是包导入的问题,请大家指教
<%@ import bill.dbweb.db.dao.*%>
<%@ import bill.dbweb.db.impl.UserDaoImpl%>
import和导入的包名需要一个空格
UserDaoImpl MyUserDaoImpl=new UserDaoImpl() ; 可能你的问题只是出现在 少个空格
谢谢楼上的各位了,十分中后开始结帐