Package com. rmol. share;
Import java. Io. ioexception;
Import java. Io. printwriter;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;
Public class login extends httpservlet {
Public void doget (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception {
String name = request. getparameter ("name ");
String Password = request. getparameter ("password ");
If (! Name. Equals ("admin ")){
Request. getrequestdispatcher ("wrong. jsp? Type = nameerr "). Forward (
Request, response );
} Else {
If (! Password. Equals ("password ")){
Request. getrequestdispatcher ("wrong. jsp? Type = passworderr ")
. Forward (request, response );
} Else {
Request. getrequestdispatcher ("index. jsp"). Forward (request,
Response );
}
}
}
Public void dopost (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception {
Doget (request, response );
}
}
Configure in XML:
<Servlet>
<Servlet-Name> login </servlet-Name>
<Servlet-class> com. rmol. Share. login </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> login </servlet-Name>
<URL-pattern>/login </url-pattern>
</Servlet-mapping>