This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Login page " Watch "Login page " New topic

Login page

sharathchandra sabbani

Joined: Oct 15, 2007
Posts: 13

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();
return map.findForward("Success");
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

<forward name="Success" path="/pageOnSuccessfulLogon"/>
<forward name="Failed" path="/backtoLoginPage"/>


John Simpson

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:
subject: Login page
It's not a secret anymore!