how to execute the below servlet with html page

how to execute the below servlet with html page

//vallidate user n pwd by validservlet


package active;

import javax.servlet.*;
import java.io.*;
import java.sql.*;


public class validservlet extends GenericServlet
{


Connection conn;
ServletConfig sc;
ServletContext scont;

public void init() throws ServletException 
{

try{

      sc=getServletConfig();
    scont=sc.getServletContext();

    String driver=scont.getInitParameter("driver");
    String url=scont.getInitParameter("url");
    String UNAME=sc.getInitParameter("UNAME");
    String PWD=sc.getInitParameter("PWD");

       Class.forName(driver);
    conn=DriverManager.getConnection(url,UNAME,PWD);

}
 catch(Exception e)
{
System.out.println(e.getMessage());
}

}

public void service(ServletRequest req, ServletResponse res) throws IOException,ServletException
{

res.setContentType("text/html");

PrintWriter out=res.getWriter();

try{

    String uname=req.getParameter("uname");
    String pwd=req.getParameter("pwd");

String sql="SELECT * FROM userlogin UNAME=? and PWD=?";

PreparedStatement pst=conn.prepareStatement(sql);

pst.setString(1,UNAME);
pst.setString(2,PWD);

ResultSet rs=pst.executeQuery();

if(rs.next())
{

RequestDispatcher rd=req.getRequestDispatcher("Admin.java");
rd.forward(req,res);

}
else
{

RequestDispatcher rd=req.getRequestDispatcher("userlogin.html");

//rd.forward(req,res);
rd.include(req,res);

System.out.println("<center><font color=red>invalid</font></center>");
}
}

catch(Exception e){}

}

public void destroy()
{

try
{conn.close();

}catch(Exception e){}

}



}


//Admin 


package active;
import javax.servlet.*;
import java.io.*;
import java.sql.*;

public class Admin extends GenericServlet
{

public void service(ServletRequest req,ServletResponse res)throws IOException,ServletException
{

res.setContentType("text/html");

PrintWriter out=res.getWriter();

System.out.println("<center> welcome to Admin </center>");

}

}

<web-app>

<content-param>
<param-name>driver</param-name>
<param-value>
sun.jdbc.odbc.JdbcOdbcDriver
</param-value>
</content-param>

<content-param>
<param-name>url</param-name>
<param-value>
jdbc:odbc:mydsn
</param-value>
</content-param>



<servlet>
<servlet-name>validservlet</servlet-name>
<servlet-class>active.validservlet</servlet-class>


<init-param>
<param-name>user</param-name>
<param-value>system</param-value>
</init-param>


<init-param>
<param-name>password</param-name>
<param-value>rammohan</param-value>
</init-param>

</servlet>


<servlet-mapping>
<servlet-name>validservlet</servlet-name>
<url-pattern>/ss</url-pattern>
</servlet-mapping>


<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>active.Admin</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>

</web-app>


//validate login.html


<html>
<body>
<body bgcolor="wheat">
<center>

<h1>Login Form</h1>

<form action="ss">
<Table>

<tr>
<td>enter name</td>
<td><Input Type="text" name="uname"></td>
</tr>

<tr>
<td>enter password</td>
<td><Input Type="password" name="pwd"></td>
</tr>
<tr>

<td><Input type="button" value="tick">remember my password</td>
</tr>


<tr>
<td><Input type="submit" value="submit"></td>
</tr>

<tr>
<td><Input type="reset" value="clear"></td>
</tr>

</Table>
</form>
</center>
</body>
</html>
View Answers

August 2, 2011 at 5:00 PM

1)login.html:

<h1>Login Form</h1>
<form action="http://localhost:8080/examples/validservlet">
<Table>
<tr>
<td>enter name</td>
<td><Input Type="text" name="uname"></td>
</tr>

<tr>
<td>enter password</td>

<td><Input Type="password" name="pwd"></td>
</tr>
<tr>

<td><Input type="checkbox" value="tick">remember my password</td>
</tr>


<tr>
<td><Input type="submit" value="submit"></td>
</tr>

<tr>
<td><Input type="reset" value="clear"></td>
</tr>

</Table>
</form>

2)validservlet.java:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class validservlet  extends HttpServlet {
  public void doGet(HttpServletRequest request,   HttpServletResponse response)  throws ServletException, IOException {
  PrintWriter pw = response.getWriter();

  String uname=request.getParameter("uname");
String pwd=request.getParameter("pwd");

 String username=getServletConfig().getInitParameter("user");
 String password=getServletConfig().getInitParameter("password");
 System.out.println(username+" "+password);
 if((uname.equals(username))&&(pwd.equals(password))){
     response.sendRedirect("Admin");
 }
 else{
     response.sendRedirect("/examples/jsp/login.html");
 }
  }
}

3)Admin.java:

import javax.servlet.*; 
import java.io.*;
import javax.servlet.http.*;

public class Admin  extends HttpServlet {
  public void doGet(HttpServletRequest request,   HttpServletResponse response)  throws ServletException, IOException {
  PrintWriter pw = response.getWriter();
response.setContentType("text/html");
PrintWriter out=response.getWriter();
pw.println("welcome to Admin");
}
}

4)Add following code to web.xml:

<servlet>
    <init-param>
 <param-name>user</param-name>
 <param-value>system</param-value>
 </init-param>
 <init-param>
 <param-name>password</param-name>
 <param-value>rammohan</param-value>
 </init-param>
<servlet-name>validservlet</servlet-name>
        <servlet-class>validservlet</servlet-class>
    </servlet>
<servlet-mapping>
        <servlet-name>validservlet</servlet-name>
        <url-pattern>/validservlet</url-pattern>
    </servlet-mapping>


<servlet>
        <servlet-name>Admin</servlet-name>
        <servlet-class>Admin</servlet-class>
    </servlet>
<servlet-mapping>
        <servlet-name>Admin</servlet-name>
        <url-pattern>/Admin</url-pattern>
    </servlet-mapping>









Related Tutorials/Questions & Answers:
how to execute the below servlet with html page
how to execute the below servlet with html page  //vallidate user n...,ServletException { res.setContentType("text/html"); PrintWriter out=res.getWriter... res)throws IOException,ServletException { res.setContentType("text/html
How to pass parametes from JSP page to HTML page? - JSP-Servlet
How to pass parametes from JSP page to HTML page?  Hi all, In my project I have one JSP page and one HTML page. In JSP page I have created HTML... with the username in HTML which I have called in JSP page. So I just want
Advertisements
how to execute this code - JSP-Servlet
how to execute this code  hi guys can any help me in executing this bank application http://www.roseindia.net/jsp/bank.shtml, i need to use any database plz tell me step-to-step procedure for executing this,i need to create
how to call servlet from html page at anchor tag ?
how to call servlet from html page at anchor tag ?  I have a very... to other page and at that place i give url of a servlet but in server that url... it is not working properly. I split and merge template. In the header part of my page i use
how to add the calendar to the dynamic rows in html or jsp page - JSP-Servlet
how to add the calendar to the dynamic rows in html or jsp page   Hi Sir, i have 3 columns in my jsp page date of payment,amount recieved,no and i have 2 button in my jsp page ADD and delete button. when i click on add
How to redirect from a HTML page?
How to redirect from a HTML page?  Hi, Is it possible to redirect from HTML page to another page on the net? I have one page and I want to redirect... to redirect to another page using HTML code. You can use the following code: <meta
how to retrieve text and images from mysql database and show on html page using jsp servlet
how to retrieve text and images from mysql database and show on html page using jsp servlet  <%@ page language="java" contentType="text/html... {color:blue} <%@ page import="java.sql.*" %> <%@ page import
Unable to execute JSP page
folder. But I could not execute the JSP page. Please help me...Unable to execute JSP page  I have written one jsp file. It contains html tags and jsp directives. I have saved the file with the extension .jsp
find out in servlet which button was clicked on an html page
find out in servlet which button was clicked on an html page  i have two buttons on my jsp page... and i want two call two seperate codes in a servlet on pressing of those 2 buttons.. how do i find out which button was clicked so
Calendar window is not coming for the Dynamic rows in html page - JSP-Servlet
Calendar window is not coming for the Dynamic rows in html page  Calendar window is not coming for the Dynamic rows in html page. I have 3 textboxes. one column is having the date textbox .I need to add the calendar icon
how to load values of html form into an excel table using java servlet?
how to load values of html form into an excel table using java servlet?   i have written a java servlet program, which has a html form to be filled. after filling the form the servlet generates a receipt and the values should
how to include an html page inside a tab
how to include an html page inside a tab  how to include an static html page inside a tab(in jquery)   Please visit the following links...;actually i want to knw how to include an google page inside a tab(suppose in 2nd
Servlet Generates HTML
Servlet Generates HTML  How Servlet Generates HTML ?   Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request. In servlet chaining, one servlet?s output is the input
How to execute shellscript in Javascript
How to execute shellscript in Javascript   Hello Can anyone please explain me how to execute shellscript in Javascript Thanks,ADS_TO_REPLACE_1
Maven Dependency html-servlet >> 0.0.2
You should include the dependency code given in this page to add Maven Dependency of cat.inspiracio >> html-servlet version0.0.2 in your project
Maven Dependency html-servlet >> 0.0.3
You should include the dependency code given in this page to add Maven Dependency of cat.inspiracio >> html-servlet version0.0.3 in your project
How to add two calendars on the same html page
How to add two calendars on the same html page  I have used the same... use single calendar for a single html page.but while implementing two calendars on same html page it doesn't work..The first calendar works but the second
Html Template - JSP-Servlet
Html Template   I use a template to design my website,but some problems arised using template.I pass flag update and insert as a hidden field on to the servlet,the response of the servlet is a jsp page.on this page template
Sending form data from HTML page to SQLserver 2005 database by calling servlet code
Sending form data from HTML page to SQLserver 2005 database by calling servlet code  Hi sir, I would like to know how to send the form data from html page to database by calling servlet code from html page .   
which version of eclipse is used to execute Servlet or JSP
which version of eclipse is used to execute Servlet or JSP  Hi Can any body tell me which version of eclipse i have to use inorder to execute Servlet or JSP. previosuly i installed eclipse 3.1 .i am having j2se 5.0 with which i
Execute PHP in HTML
. In the foregoing paragraph we have seen how to execute php in html page. Now lets find out... it’s better to execute php in html page instead of renaming...Execute PHP in HTML In this tutorial you will learn about the different ways
send HTML Email with jsp and servlet
send HTML Email with jsp and servlet  Can You please show me how to send html Email using JSP and Servlet thank you
how to pass form values from javascript of html page to jsp page
how to pass form values from javascript of html page to jsp page   This is my sample html page which contains inline javascript which calculates the geocode and tries to return the lattitude and longitude .But my question is how
How to extract HTML elements from a page?
HTML Scrapping: How to extract HTML elements from a page? In this tutorial we are going to teach you how to extract the HTML elements from a web page... for extracting HTML element from a page. We will extract the data from the html table
html and servlet file
html and servlet file  where to place the html and the servlet class... html file with the jsp files amd servlet file insdie classes folder of tomcat. You have to specify the full path of servlet on html action if you want to call
How to extract HTML elements from a page?
HTML Scrapping: How to extract HTML elements from a page? In this tutorial we are going to teach you how to extract the HTML elements from a web page...; So, we have learned how to extract the html elements from the web page
Populate value into HTML page
Populate value into HTML page  Hi, How to populate values from one html page table to another html page..? Thanks
How to create simple HTML Login Page?
with JavaScript. You will  learn How to create a simple HTML login page... How to make Spring web Login form? HTML Login Page Code...Simple HTML Login Page- Create a Simple HTML Login page and validate
How to create simple HTML Login Page?
with JavaScript. You will  learn How to create a simple HTML login page...Simple HTML Login Page- Create a Simple HTML Login page and validate...;/form> </body> </html> You can run this html page in web
divide html page
divide html page   how to divide html page into 3 parts without using frames
how to execute jsp and servlets with eclipse
how to execute jsp and servlets with eclipse  hi kindly tell me how to execute jsp or servlets with the help of eclipse with some small program
How map the first_servlet to second_servlet - JSP-Servlet
How map the first_servlet to second_servlet  Hello, I have two questions. 1.How I want map the second_servlet by first_servlet. My Html page map... have a function which define in second_servlet. How that fuction which define
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)
replies back to the HTML page as "Login is successful". So my question is how to pass...How to pass and catch HTML parameters to a Java program using REST services... servlet/jsp). Also how to use hibernate criteria? Please help. Its very urgent
Version of cat.inspiracio>html-servlet dependency
List of Version of cat.inspiracio>html-servlet dependency
simplest HTML page
simplest HTML page  What is the simplest HTML page
html form - JSP-Servlet
html form  how to retrieve database value in dropdown list box placed in html form  Hi friend, Visit for more information. http://www.roseindia.net/jsp/ Thanks
page breaks in HTML
page breaks in HTML  How do I specify page breaks in HTML
page breaks in HTML
page breaks in HTML  How do I specify page breaks in HTML
Include Static HTML Page in JSP
Include Static HTML Page in JSP   ... html page in jsp. In JSP, there are two ways to include another web resource. 1...;static.html" %> tag is used to include html page. The following
how to execute jsp and servlets with eclipse
how to execute jsp and servlets with eclipse  hi kindly tell me how to execute jsp or servlets with the help of eclipse with some small program.../hibernate/hibernate4/hibernate4ExampleEclipse.shtml Going through this link you may understand how
how to generate captcha in jsp page ? - JSP-Servlet
how to generate captcha in jsp page ?  hi friends, i would like to implement Captcha in login screen. i'm unsing struts. could you please give some sample codes to implement this. Thank you Ganesh  Hi, This link
Servlet refresh page
Servlet refresh page In this example we will show you how you can refresh your page from setting the refresh attribute from a servlet. response.setHeader... refresh code into HTML page. Read more at http://www.roseindia.net/software
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly   index.html <..." content="text/html; charset=UTF-8"> </head> <script language
javascript-html - JSP-Servlet
javascript-html  i want to dynamically create textfield with option button as another/remove when user presses in jsp page which will be in table.for example table contains one row with 2 columns,one textfield,second dropdown
javascript-html - JSP-Servlet
javascript-html  i want to dynamically create textfield with option button as another/remove when user presses in jsp page which will be in table.for example table contains one row with 2 columns,one textfield,second dropdown
html - JSP-Servlet
m not able to understand how to do it on web sever i m trouble pls solve my
Maven dependency for cat.inspiracio - html-servlet version 0.0.2 is released. Learn to use html-servlet version 0.0.2 in Maven based Java projects
-servlet released The developers of   cat.inspiracio - html-servlet project... version of  cat.inspiracio - html-servlet library is 0.0.2. Developer can use this version ( cat.inspiracio - html-servlet version 0.0.2 ) in their Java
Maven dependency for cat.inspiracio - html-servlet version 0.0.3 is released. Learn to use html-servlet version 0.0.3 in Maven based Java projects
-servlet released The developers of   cat.inspiracio - html-servlet project... version of  cat.inspiracio - html-servlet library is 0.0.3. Developer can use this version ( cat.inspiracio - html-servlet version 0.0.3 ) in their Java
HTML login page code
HTML login page code  Hi all, I am writing my first HTML JavaScrip validation page called "UserLogin.html". So, please guide me how to validate user... the complete HTML JavaScript code for User Login Page. Thanks in Advance!   
How to Send particular error to another page in Servlet from web.xml
How to Send particular error to another page in Servlet from web.xml  How to Send particular error to another page in Servlet from web.xml  ...;/location> </error-page> You can also send error from Servlet

Ads