我在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();
}
}
}
和login.html是:
<form action="dologin" namw="dologin">
Username:<input type="text" name="usename">
Paswword:<input type="text" name="pass">
</form>
我已将web.xml配置为:
<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>
我正在使用myeclipse IDE如果运行我收到此错误就像supermMail不可用超级邮件是我的项目名称。请帮助我。
答案 0 :(得分:0)
你可以这样做,像我一样:
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/pages/Login.xhtml</form-login-page>
</form-login-config>
</login-config>