servlet编译时出错,老是提示软件包lft.bean不存在
我写的是一个登陆验证的servlet,里面调用了classes\lft\bean下的DatabaseConn类(用于连接数据库)
servlet代码如下:
package lft.servlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import lft.bean.*;
public class CheckServlet
extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=GBK";
public void init()
throws ServletException
{
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException
{
String a = request.getParameter("username");
String b = request.getParameter("userpwd");
Connection conn = DatabaseConn.getConnection( );
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select username,password from user" );
String uname = rs.getString("username");
String psw = rs.getString("password");
if (uname.equals(a) && psw.equals(b))
{
response.sendRedirect("welcome.jsp");
}
else
{
response.sendRedirect("index.html");
}
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException
{
doGet(request, response);
} //Clean up resources
public void destroy()
{
}
}
问题出在哪里,请高人指点!!
我写的是一个登陆验证的servlet,里面调用了classes\lft\bean下的DatabaseConn类(用于连接数据库)
servlet代码如下:
package lft.servlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import lft.bean.*;
public class CheckServlet
extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=GBK";
public void init()
throws ServletException
{
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException
{
String a = request.getParameter("username");
String b = request.getParameter("userpwd");
Connection conn = DatabaseConn.getConnection( );
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select username,password from user" );
String uname = rs.getString("username");
String psw = rs.getString("password");
if (uname.equals(a) && psw.equals(b))
{
response.sendRedirect("welcome.jsp");
}
else
{
response.sendRedirect("index.html");
}
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException
{
doGet(request, response);
} //Clean up resources
public void destroy()
{
}
}
问题出在哪里,请高人指点!!
解决方案 »
- struts2<s:if test=${pb.pageTotal>0}>出现问题 如果我这样写是正确的<s:if test=#request.pb.pageT
- 在java EE 5.0 下开发java mail碰到的问题及解决方案
- 关于 HTTP Status 404 - Servlet action is not available的问题
- 关于javamail的棘手问题
- 谁给个静态分页的思路??谁给个静态分页的思路??
- 求水晶报表的Java SDK,着急,请大家帮忙
- jsp中如何判断是哪个按钮提交的
- 求救
- 如何让页面自动来根据用户输入的URL来跳转?
- 急!请问象本论坛这样,左边选择论坛后,右边就出现相应的内容是怎么做出来的哟。
- 初学JSP遇到的简单问题
- 如何实现这种字符截取?
try{ //加入
while(rs.next()){//加入,重点是这一句
String uname = rs.getString("username");
String psw = rs.getString("password");
}//加入
}catch(SQLException e){//加入
}//加入
public static getConnection(){
...
}
是这样吗?
package lft.bean;import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;//一个用于查找数据源的工具类。
public class DatabaseConn {
public static synchronized Connection getConnection() throws Exception
{
try
{
Context initCtx = new javax.naming.InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/lftsql"); ;
return ds.getConnection();
}
catch(SQLException e)
{
throw e;
}
catch(NamingException e)
{
throw e;
}
}}
DatabaseConn下getConnection( );如何定义的?
public static Connection getConnection(){
...
}