1,105,644 Community Members

JSP Database Connection MS-ACCESS

Member Avatar
sagar2dumbre
Newbie Poster
10 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello i am developing a web app in JSP as front end and ms-access as back end..i hv login.jsp which contains username & password which will be validated in access database upon success user.jsp will be shown..i hv been done with jsp page design..but don't know abt database connectivity..can any1 help
.
.
one more thing..
I am on Windows 7 (64 bit)
JDK,JRE (64 bit)
Netbeans 7 (32 bit)
Office 2010 (32 bit)....now is there any driver issue involved in JDBC-ODBC driver for 64 bit ???...Coz i cudnt see any access driver in ODBC Data Source (Control Panel)
Your Help will be appreciated..!!

Member Avatar
peter_budo
Code tags enforcer
7,935 posts since Dec 2004
Reputation Points: 2,502 [?]
Q&As Helped to Solve: 1,028 [?]
Skill Endorsements: 66 [?]
Moderator
Featured
 
0
 

there maybe someone willing to help if you post your code.

PS: would be good idea to use different database like MySQL as you are unlikely to find person on Unix with Access DB

Member Avatar
sagar2dumbre
Newbie Poster
10 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Login.jsp

<%-- 
    Document   : login
    Created on : Jan 22, 2012, 4:17:51 PM
    Author     : Dumbre
--%>

<%@page language="java" import="java.net.*" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>::Flat Booking System :: Indian Oil Corporation Limited</title>
        <link rel="stylesheet" type="text/css" href="css/style.css"/>
        <link rel="icon" type="image/png" href="images/favicon.png"/> 
    </head>    
    <body>
        <form method="POST" action="login">
            <div class="top">
        <jsp:include page="resources/header.jsp" ></jsp:include>
            </div>
        <h1 id="caption">:: <u>Flat Booking System</u> ::</h1>
          <table id="login-box" >
            <tr>
                <td colspan="2">
                    <div id="headline"> <u><i>Central Login </i></u></div>
                </td>
            </tr>
            <tr>
                <td id="logo1">
                    <img id="logo" src="images/logo.png"/>
                </td>
                <td id="login-form">
                        <table id="form">
                            <tr><td id="username-label">
                                    <label for="username" id="username-label"><small><b>USERNAME</b></small></label>
                                </td>
                                <td id="username-text">
                                    <input type="text" accesskey="u" size="32" tabindex="1" name="username" id="username"/>
                                </td>
                            </tr>
                            <tr><td id="password-label">
                                    <label for="password" id="password-label"><small><b>PASSWORD</b></small></label>
                                </td>
                                <td id="password-text">
                                    <input type="password" accesskey="p" autocomplete="off" size="32" tabindex="2" name="password" 
id="password"/>
                                </td>
                            </tr>
                            <tr><td colspan="2" align="center" id="submit">
                                    <input type="submit" value="LOGIN" accesskey="l" tabindex="4" id="login-submit"/>
                                </td>
                            </tr>
                        </table>
               </td>
            </tr>
        </table>
         </div>
        </form>
    </body>
</html>

LoginServlet.java

package Validate;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginServlet extends HttpServlet {
    
    String uname="";
    String pass="";
    String url = "jdbc:odbc:FBS";
    Connection conn=null;
    Statement st=null;
    ResultSet rs=null;
    String classPath = "sun.jdbc.odbc.JdbcOdbcDriver";
    @Override public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try{
            response.setContentType("text/html");
            HttpSession session = request.getSession(true);
            Class.forName(classPath);
            conn=DriverManager.getConnection(url);
            uname=request.getParameter("username");
            pass=request.getParameter("password");
            st=conn.createStatement();
            rs=st.executeQuery("select * from user_login where UserName='"+uname+"' and Password='"+pass+"'");
            while(rs.next())
                        {
                         session.setAttribute("uname", uname);
                         session.setMaxInactiveInterval(120);
                         RequestDispatcher dispatcher=request.getRequestDispatcher("/flat_status.jsp");
                         dispatcher.forward(request, response);
                        }
                        rs.close();
                        st.close();
                        conn.close();
        }
        catch(Exception e)
                {
         System.out.println(e.getMessage());    
        }
        
    }
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fmt="http://java.sun.com/jsp/jstl/fmt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
            <param-name>debug</param-name>
            <param-value>2</param-value>
        </init-param>
        <init-param>
            <param-name>detail</param-name>
            <param-value>2</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>LoginServlet</servlet-name>
        <servlet-class>Validate.LoginServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>LoginServlet</servlet-name>
        <url-pattern>/login</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
</web-app>
Member Avatar
sagar2dumbre
Newbie Poster
10 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

there maybe someone willing to help if you post your code.

PS: would be good idea to use different database like MySQL as you are unlikely to find person on Unix with Access DB

if Username & Password are correct (matched with db) then new jsp page flat_status.jsp should open

and I hv been told 2 use db as access...:sad:

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: