简体   繁体   中英

How to configure the web.xml file?

I have created login page in servlet:

public class dologin extends HttpServlet
{
    static Connection con;
    static String query =null;
    static ResultSet rs;
    static PreparedStatement pstmt;

    String user=null;
    String passwd = null ;

    public void init(ServletConfig sc)
    {
        try
        {
            super.init(sc);
            /*Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            System.out.println("class loaded ... ");
            con=DriverManager.getConnection("jdbc:odbc:Odbc_mailing");
            System.out.println("connected ... ");
            st=con.createStatement();
            System.out.println("stmt created ... ");*/




        }
        catch(Exception e)
        {
           e.printStackTrace();
        }
    }

    public void service(HttpServletRequest hreq ,HttpServletResponse hrep)
    {
        boolean flag=false;
        try
        {

            String s1=hreq.getParameter("smid");
            String s2=hreq.getParameter("smpw");
            System.out.println("s1 : "+ s1+"s2 : "+s2);
            Cookie logincook=new Cookie("logincook",s1);
            Cookie pwdcook=new Cookie("pwdcook",s2);
            hrep.addCookie(logincook);
            hrep.addCookie(pwdcook);
            System.out.println("logincook :"+ logincook);
            System.out.println("pwd:"+ pwdcook);
            ServletOutputStream sos = hrep.getOutputStream();
             String query="select *  from login where username=?";

            con=DBConnection.getConnection();
            pstmt=con.prepareStatement(query);
            pstmt.setString(1, s1); 

            rs=pstmt.executeQuery();  //fname,pass1
            System.out.println("query executed ... rs "+rs);
            while(rs.next())
            {
                System.out.println("in while loop");
            //  user=rs.getString(1);
                //passwd=rs.getString(2);
                System.out.println("user : "+ user + "passwd : "+passwd);
                if((user.equals(s1))&&(passwd.equals(s2)))
                {
                    flag=true;
                    break;

                }
            }
        System.out.println("Aft while loop flag : "+ flag);
        if (flag==false)
            {
                sos.println("<h3> You are an invalid user </h3>");
                hrep.setHeader("Refresh", "2 URL=/supermail/index.html");
            }
        if(flag==true){
                hrep.sendRedirect("/supermail/inbox.html");
            }
        flag = false;
       }
       catch(Exception ex)
       {
           ex.printStackTrace();
           }

       }
    }

and login.html is:

<form action="dologin" namw="dologin">
Username:<input type="text" name="usename">
Paswword:<input type="text" name="pass">
</form>

I have configured the web.xml like:

<web-app>
    <servlet>
        <servlet-name>dologin</servlet-name>
        <servlet-class>dologin</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>dologin</servlet-name>
        <url-pattern>/dologin</url-pattern>
        </servlet-mapping>
</web-app>

I am using myeclipse IDE if run the I am getting this error like supermMail is not available super mail is my project name.please help me with this.

您可以像我一样这样做: <login-config> <auth-method>FORM</auth-method> <form-login-config> <form-login-page>/pages/Login.xhtml</form-login-page> </form-login-config> </login-config>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM