zoukankan      html  css  js  c++  java
  • Jsp-Servlet 那一大堆事儿--1

    为毛全局变量声明时初始化在try内不能用?

    import javax.servlet.http .*;
    import java.io.*;
    import javax.servlet.*;
    import java.sql.*;
    public class LoginServlet extends HttpServlet{
        public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
            String errMsg = "";
            RequestDispatcher rd;
            String username = "";
            username = request.getParameter("username");
            String pass = "";
            pass = request.getParameter("pass");
            try{
                DbDao dd = new DbDao("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/poetry","root","root");
                ResultSet rs = dd.query("select password from t_account where account = ?",username);
                if(rs.next()){
                    if(rs.getString("password").equals(pass)){
                        HttpSession session = request.getSession(true);
                        session.setAttribute("name",username);
                        rd = request.getRequestDispatcher("/welcome.jsp");
                        rd.forward(request,response);
                    }else{
                        errMsg += "您的用户名密码不符合,请重新输入";
                    }
                }else{
                    errMsg += "您的用户名不存在,请先注册";
                }
            }catch(Exception e){
                e.printStackTrace();
            }
            if(errMsg != null &&  !errMsg.equals("")){
                rd = request.getRequestDispatcher("/login.jsp");
                request.setAttribute("err",errMsg);
                rd.forward(request,response);
            }
        }
    }
  • 相关阅读:
    xml的语法与创建
    smarty实现缓存
    Smarty中一些标签的使用
    smarty中的变量使用
    商品中的分页类
    引入百度编辑器
    VB.NET操作Word大全
    Android 自带图标库 android.R.drawable
    DataGridViewComboxCell值无效 的原因
    windows7/win7 iis的安装与配置(图解教程)
  • 原文地址:https://www.cnblogs.com/ClassNotFoundException/p/6024596.html
Copyright © 2011-2022 走看看