• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Login page

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the struts samples code. Its all there, just take your time and read through it.
reply
    Bookmark Topic Watch Topic
  • New Topic