Servlet Config

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>WebConfig</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

  <servlet>

    <description></description>

    <display-name>conServlet</display-name>

    <servlet-name>conServlet</servlet-name>

    <servlet-class>tis.demo.conServlet</servlet-class>

     <init-param> 

       <param-name>d1</param-name> 

       <param-value>com.mysql.jdbc.Driver</param-value> 

     </init-param> 

     <init-param> 

       <param-name>d2</param-name> 

       <param-value>jdbc:mysql://localhost:3306/emp</param-value> 

     </init-param> 

  </servlet>

  <servlet-mapping>

    <servlet-name>conServlet</servlet-name>

    <url-pattern>/conServlet</url-pattern>

  </servlet-mapping>

</web-app>

 

 

 

 

 

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

    pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html> 

   <head> 

     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 

     <title>Login Page</title> 

   </head> 

   <body> 

     <h1>Login</h1> 

     <form action="conServlet"> 

      Username:<input type="text" name="t1"><br> 

      Password:<input type="password" name="t2"><br> 

      <input type="submit" value="login" > 

      </form> 

   </body> 

 </html> 

 

 

 

package tis.demo;

 

import java.io.IOException;

import java.io.PrintWriter;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.Enumeration;

 

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

public class conServlet extends HttpServlet {

                private static final long serialVersionUID = 1L;

      

   

    public conServlet() {

        super();

     

    }

 

               

                protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {

                                PrintWriter out=response.getWriter(); 

                     String s1=req.getParameter("t1"); 

                     String s2=req.getParameter("t2");

                     

                     String dd1=getServletConfig().getInitParameter("d1");

                     String dd2=getServletConfig().getInitParameter("d2");

                     ServletConfig config=getServletConfig(); 

                     Enumeration ee=config.getInitParameterNames(); 

                    

                     while(ee.hasMoreElements()) 

                     { 

                       String s=(String)ee.nextElement(); 

                       out.println(config.getInitParameter(s)); 

                     } 

                     try{ 

                       Class.forName(dd1); 

                       Connection connection=DriverManager.getConnection(dd2,"root","admin"); 

                       Statement st=connection.createStatement(); 

                       ResultSet rs=st.executeQuery("select * from login where Uname='"+s1+"'and Upass='"+s2+"'"); 

                       if (rs.next()) 

                       out.print("Welcome! "+s1); 

                       else 

                       out.print("invalid user"); 

                       } 

                     catch(Exception e){ 

                       out.print(e); 

                     } 

                }

 

                protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                               

                }

 

}



This e-mail and any attached files are confidential, proprietary, and may also be legally privileged information, and are intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient of this e-mail, please send it back to the person who sent it to you and delete the e-mail and any attached files and destroy any copies of it; you may call us immediately at + 91 22 6643 8000 or email us at IT-Security@tatainteractive.com

Tata Interactive Systems and/or any of its sister companies owns no responsibility for the views presented in the e-mail and any attached files unless the sender mentions so, with due authority of Tata Interactive Systems.

Unauthorized reading, reproduction, publication, use, dissemination, forwarding, printing or copying of this e-mail and its attachments is prohibited.

We have checked this message for any known viruses; however we decline any liability, in case of any damage caused by a non-detected virus.

For more details about our company, visit http://www.tatainteractive.com.

Comments

Popular Posts