aspose file tools*
The moose likes Struts and the fly likes Login page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Login page " Watch "Login page " New topic
Author

Login page

sharathchandra sabbani
Greenhorn

Joined: Oct 15, 2007
Posts: 13
Hi

I'm new to struts...I want to create a login page with the username and pwd, these both values are to be checked with the database username and pwd.Please help how to write the code for it...Thankyou...
prakash chauhan
Ranch Hand

Joined: Jun 22, 2007
Posts: 81
Can be done using declarative security (using DD) and having the Authenticatio type set to Basic or Form and defining your own Realm for the user-pwd database however as i know of programmatic security , you can create an actionservlet lets say LoginSevlet and in the execute you can call a method(helper)that checks for user authentication:
(if somebody knows how to use Declarative Security without using the tomcat-users.xml file , i ll appreciate that)
-------------------------------------------------------------------------
The code should look something like this
-------------------------------------------------------------------------

class LoginServlet extends Action{
ActionForward execute(ActionMapping map, ActionForm form,HttpServletRequest req, HttpServletResponse res) throws Exception{
LoginForm loginForm=(LoginForm)form;
String user=loginForm.getUser();
String pwd= loginForm.getPwd();
if(isAuthenticated(user,pwd)){
return map.findForward("Success");
}else{
return map.findForward("Failed");
}
}

private isAuthenticated(String user,Sring pwd){
//make database conection and verify user name-password
return true/false;

}
}
------------------------------------------------------------------

This LoginServlet will be called from the <html:form action="loginSerlet">
and should have the following mapping in struts-config.xml file

---------------------------------------------------------------------------
<action
path="/loginServet"
type="com.prakash.LoginServlet">
<forward name="Success" path="/pageOnSuccessfulLogon"/>
<forward name="Failed" path="/backtoLoginPage"/>
</action>



-------------------------------------------------------------------------

-Thanks
John Simpson
Greenhorn

Joined: Sep 10, 2007
Posts: 25
Look at the struts samples code. Its all there, just take your time and read through it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Login page