韩顺平setvlet代码.docx
- 文档编号:5713013
- 上传时间:2022-12-31
- 格式:DOCX
- 页数:26
- 大小:20.19KB
韩顺平setvlet代码.docx
《韩顺平setvlet代码.docx》由会员分享,可在线阅读,更多相关《韩顺平setvlet代码.docx(26页珍藏版)》请在冰豆网上搜索。
韩顺平setvlet代码
packagezonghe2;
importjava.sql.Connection;
importjava.sql.DriverManager;
//从数据库得到链接
publicclassConnDB
{
privateConnectionct=null;
publicConnectiongetConn()
{
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
ct=DriverManager.getConnection("jdbc:
sqlserver:
//localhost:
1433;databaseName=h_servlet","sa","myledayong");
}
catch(Exceptione)
{
e.printStackTrace();
}
returnct;
}
}
packagezonghe2;
importjava.io.IOException;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassDelUserCLextendsHttpServlet
{
@Override
protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)
throwsServletException,IOException
{
try
{
resp.setContentType("text/html;charset=gbk");
//调用userbeancl的删除用户的方法
UserBeanCLubc=newUserBeanCL();
//接收从wel.java中传递的id
Stringid=req.getParameter("userId");
if(ubc.delUser(id)==true)
{
//删除成功
resp.sendRedirect("OK");
}
else
{
//删除失败
resp.sendRedirect("Error");
}
}
catch(Exceptione)
{
e.printStackTrace();
}
}
@Override
protectedvoiddoPost(HttpServletRequestreq,HttpServletResponseresp)
throwsServletException,IOException
{
this.doGet(req,resp);
}
}
packagezonghe2;
importjava.io.IOException;
importjava.io.PrintWriter;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassErrorextendsHttpServlet
{
@Override
protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)
throwsServletException,IOException
{
try
{
//解决中文乱码
resp.setContentType("text/html;charset=gbk");
PrintWriterpw=resp.getWriter();
//返回登录界面
pw.println("");
pw.println("
pw.println("
pw.println("
操作失败
");pw.println("
pw.println("");
pw.println("