level 1
落叶あ痕
楼主
下面是servlet处理文件,连接的是mysql数据库,怎样改成连接到ACCESS的啊
我自己改了调试通不过,
package zieckey.login.servlet;
import java.sql.Statement;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet extends HttpServlet implements Servlet
{
public LoginServlet ()
{
// TODO Auto-generated constructor stub
}
/*
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet ( HttpServletRequest arg0, HttpServletResponse arg1 )
throws ServletException, IOException
{
}
/*
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doPost ( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
response.setContentType ( "text/html" );
String result = "";
// 获取用户名
String sUserName = request.getParameter ( "txtUserName" );
if ( sUserName == "" || sUserName == null || sUserName.length ( ) > 20 )
{
try
{
result = "请输入用户名(不超过20字符)!";
request.setAttribute ( "ErrorUserName", result );
response.sendRedirect ( "login.html" );
} catch ( Exception e )
{
}
}
// 获取密码
String sPasswd = request.getParameter ( "txtPassword" );
if ( sPasswd == "" || sPasswd == null || sPasswd.length ( ) > 20 )
{
try
{
result = "请输入密码(不超过20字符)!";
request.setAttribute ( "ErrorPassword", result );
response.sendRedirect ( "login.html" );
} catch ( Exception e )
{
}
}
// 登记JDBC驱动程序
try
{
Class.forName ( "org.gjt.mm.mysql.Driver" ).newInstance ( );
} catch ( InstantiationException e )
{
// TODO Auto-generated catch block
e.printStackTrace ( );
System.out.println ("InstantiationException");
} catch ( IllegalAccessException e )
{
// TODO Auto-generated catch block
e.printStackTrace ( );
System.out.println ("IllegalAccessException");
2011年12月20日 10点12分
1
我自己改了调试通不过,
package zieckey.login.servlet;
import java.sql.Statement;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet extends HttpServlet implements Servlet
{
public LoginServlet ()
{
// TODO Auto-generated constructor stub
}
/*
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet ( HttpServletRequest arg0, HttpServletResponse arg1 )
throws ServletException, IOException
{
}
/*
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doPost ( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
response.setContentType ( "text/html" );
String result = "";
// 获取用户名
String sUserName = request.getParameter ( "txtUserName" );
if ( sUserName == "" || sUserName == null || sUserName.length ( ) > 20 )
{
try
{
result = "请输入用户名(不超过20字符)!";
request.setAttribute ( "ErrorUserName", result );
response.sendRedirect ( "login.html" );
} catch ( Exception e )
{
}
}
// 获取密码
String sPasswd = request.getParameter ( "txtPassword" );
if ( sPasswd == "" || sPasswd == null || sPasswd.length ( ) > 20 )
{
try
{
result = "请输入密码(不超过20字符)!";
request.setAttribute ( "ErrorPassword", result );
response.sendRedirect ( "login.html" );
} catch ( Exception e )
{
}
}
// 登记JDBC驱动程序
try
{
Class.forName ( "org.gjt.mm.mysql.Driver" ).newInstance ( );
} catch ( InstantiationException e )
{
// TODO Auto-generated catch block
e.printStackTrace ( );
System.out.println ("InstantiationException");
} catch ( IllegalAccessException e )
{
// TODO Auto-generated catch block
e.printStackTrace ( );
System.out.println ("IllegalAccessException");