它们主要负责日常的网页运营和管理。
此外还有网页的四要素,分别是网站结构、网站功能、网站内容及网站服务。
给你一个小例子看看就明白了。获取用户输入参数,然后进行数据库查询,查询成功则登录成功12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
public class HandleLogin extends HttpServlet{private String backNews = "" //登录状态返回信息 public void init(ServletConfig config) throws ServletException{super.init(config) } public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{request.setCharacterEncoding("utf-8") response.setCharacterEncoding("utf-8") Login loginBean = null //JavaBeanHttpSession session = request.getSession(true) try {loginBean = (Login) session.getAttribute("login") if(loginBean == null){loginBean = new Login() session.setAttribute("login", loginBean) }} catch (Exception e) {loginBean = new Login() session.setAttribute("login", loginBean) } String id = request.getParameter("id").trim() String password = request.getParameter("password").trim() boolean loginOk = loginBean.isLoginSuccess()if(loginOk&&(id.equals(loginBean.getId())&&(password.equals(loginBean.getPassword())) )){backNews = "尊敬的会员:"+id+",您已经登录,无需重复登录!" loginBean.setBackNews(backNews) }else{boolean chkLength = id.length()>0 &&password.length()>0 //判断用户名和密码是否为空if(chkLength){//连接数据库进行查询验证登录是否正确Connection connection = DbConn.getConnection() try {PreparedStatement pStatement = connection.prepareStatement("select id from member where id=? and password =?") pStatement.setString(1, id) pStatement.setString(2, password) ResultSet resultSet = pStatement.executeQuery()if(resultSet.next()){backNews = "登录成功" loginBean.setId(id) loginBean.setPassword(password) loginBean.setLoginSuccess(true) loginBean.setBackNews(backNews) }else{backNews = "您输入的用户名不存在,或密码不匹配" loginBean.setId(id) loginBean.setLoginSuccess(false) loginBean.setBackNews(backNews) }connection.close() } catch (SQLException e) {backNews = "您输入的用户名不存在,或密码不匹配" loginBean.setId(id) loginBean.setLoginSuccess(false) loginBean.setBackNews(backNews) } }else{backNews = "用户名和密码不能为空" loginBean.setId(id) loginBean.setLoginSuccess(false) loginBean.setBackNews(backNews) }} RequestDispatcher dispatcher = request.getRequestDispatcher("showLoginMess.jsp") dispatcher.forward(request, response) } public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{doPost(request, response) }}
代码挺粗糙的,大概意思就这样的,将就着看吧