|
Login form authentication using Struts with database
|
|
01-21-2012, 10:22 PM
(This post was last modified: 01-21-2012 11:00 PM by mjm.)
Post: #1
|
|||
|
|||
|
Login form authentication using Struts with database
how to create a login form and authenticate using struts with database First import the required tld's that i have included in project so don't worry about that. Lets create a simple form where it gets username and password as input <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> <b><font color="Green">Tutorial Pruodly Presented by <a href="http://s2sgateway.com">http://s2sgateway.com</a></font></b> <html:form action="/login" > Username<html:text property="username"/> Password<html:password property="password"/> <html:submit/> </html:form> </body> </html> Now create two pages for ex success.jsp for authenticated page and failure.jsp for failure message and re-login option in that page Lets create the struts-config.xml file The Action form class contains getter and setter methods,The action class code contains the call to form class and connection to mysql and check the username and password are correct. package com.s2sgateway.action; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.s2sgateway.form.LoginForm; public class LoginAction extends Action { String r=""; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { LoginForm loginForm = (LoginForm) form; String username=loginForm.getUsername(); String password=loginForm.getPassword(); ResultSet rs; try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/struts","root","root"); Statement st=con.createStatement(); rs=st.executeQuery("select * from login"); while(rs.next()) { System.out.println("Successfull"); if((username.equals(rs.getString(1)))&&(password.equals(rs.getString(2)))) { return mapping.findForward("success"); } else { return mapping.findForward("failure"); } } } catch(Exception e) {} return mapping.findForward®; }} To run this program you need mysqlconnector i have added in lib folder.For connection create a database named "struts" and create table named login with username and password fields Download the Struts login project by clicking link below ![]() It contains the war file import in to your eclipse and run this project.Happy coding.
walkins in bangalore
walkins in chennai Note: For all the jobs, make sure to call the given number and attend the walkin. if you get this information is not accurate, please reply to this thread to help others. |
|||
The following 1 user says Thank You to mjm for this post:ganga (03-29-2012) |
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
|
04-27-2012, 03:57 PM
Post: #2
|
|||
|
|||
|
RE: Login form authentication using Struts with database
I am trying to download source code, but getting link not found error.
Kindly give us new link location so that download source code. Thanks Alex |
|||
|
« Next Oldest | Next Newest »
|
![]() |
|||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
| Possibly Related Threads... | |||||
| Thread: | Author | Replies | Views: | Last Post | |
| Struts hiberanate integration tutorial part2 | rajasri | 9 | 1,438 |
05-02-2012 04:29 PM Last Post: admin |
|
| Struts hiberanate integration tutorial part2 | admin | 1 | 318 |
05-02-2012 02:36 PM Last Post: lalithakotha |
|
| Simple Struts-Hibernate Integration tutorial to insert values | rajasri | 2 | 3,538 |
01-15-2012 01:40 PM Last Post: mukesh1234 |
|
| Simple Struts Example | rajasri | 0 | 397 |
12-14-2011 11:17 AM Last Post: rajasri |
|
| Struts Dispatch Action Tutorial with example | rajasri | 0 | 1,386 |
12-12-2011 08:56 PM Last Post: rajasri |
|
| How to export data as pdf in struts using displaytags | rajasri | 0 | 1,018 |
12-12-2011 06:38 PM Last Post: rajasri |
|
User(s) browsing this thread: 1 Guest(s)



![[Image: Download.gif]](http://s2sgateway.com/Download.gif)



![[-]](images/royal_red/collapse.gif)







