Step 1: In Projects Window double click on index.jsp file present in Web Pages Folder and Write Following Html Code.
Inside Form tag we have written action where we have passed NewServlet that is Url-Pattern of Servlet-Name NewServlet that will Redirect current page to NewServlet.java Page.
Second thing inside form tag is method which are of two types:
a) Get(default)
b) Post
Get will also work if we don't pass any method property inside form tag and if we are using Get method then on submit button click when page Redirect to NewServlet.java you can see values of username and password on Navigation bar that is Security Risk that's why we use post method to hide entered values.
Get and Post methods are also used to call doGet() and doPost() methods respectively on Servlet page.
Step 2: Double Click on Web.Xml file in WEB-INF Folder and click on XML tab.
Here You can also Change Url-Pattern of your Servlet and Welcome-file of your project by replacing index.jsp with your file inside welcome-file tag.
Step 3: NewServlet.java code
Download Code Link 1
Download Code Link 2
Here we are using getParameter() to get username, password and Storing them in String s1 and s2 then comparing Sting s1 value with Himanshu(username) and String s value with Bhasin(password) using equals() method, if username and password both are true then output will be Welcome Himanshu(username) otherwise it'll display InValid user!
java.io Package
Inside Form tag we have written action where we have passed NewServlet that is Url-Pattern of Servlet-Name NewServlet that will Redirect current page to NewServlet.java Page.
Second thing inside form tag is method which are of two types:
a) Get(default)
b) Post
Get will also work if we don't pass any method property inside form tag and if we are using Get method then on submit button click when page Redirect to NewServlet.java you can see values of username and password on Navigation bar that is Security Risk that's why we use post method to hide entered values.
Get and Post methods are also used to call doGet() and doPost() methods respectively on Servlet page.
Step 2: Double Click on Web.Xml file in WEB-INF Folder and click on XML tab.
Here You can also Change Url-Pattern of your Servlet and Welcome-file of your project by replacing index.jsp with your file inside welcome-file tag.
Step 3: NewServlet.java code
Download Code Link 1
Download Code Link 2
Here we are using getParameter() to get username, password and Storing them in String s1 and s2 then comparing Sting s1 value with Himanshu(username) and String s value with Bhasin(password) using equals() method, if username and password both are true then output will be Welcome Himanshu(username) otherwise it'll display InValid user!
java.io Package
public class IOException extends Exception
Signals
that an I/O exception of some sort has occurred. This class is the
general class of exceptions produced by failed or interrupted I/O
operations.
public class PrintWriter extends Writer
Prints
formatted representations of objects to a text-output stream. This
class implements all of the print methods found in PrintStream.
javax.servlet Package
public class ServletException extends Exception
Defines a general exception a servlet can throw when it encounters difficulty.
java.io.PrintWriter
public void println()
Terminates
the current line by writing the line separator string. The line
separator string is defined by the system property line.separator, and
is not necessarily a single newline character ('\n').More Servlet Topics :
- Introduction : Servlet Interface
- Java Package javax.servlet(Interfaces,Classes and Methods)
- Java Package javax.servlet.http (Interfaces,Classes and Methods)
- How to Create a Web Application using NetBeans and Apache Tomcat Server
- Basic Program using HttpServlet Class
- Basic Login Program using JSP and GenericSevlet class
- Login using JDBC,Servlet with NetBeans and Oracle
- SevletConfig Interface using JDBC,NetBeans 6.9 and Oracle 10g
- Validation on TextField using JavaScript and Print command using servlet on NetBeans
- ServletContext Interface
- RequestDispatcher Interface and SendRedirect() Method
- Session Tracking
- Session Tracking using Cookies
- Session Tracking using HttpSession Interface
- Session Tracking using URL Rewriting
- Session Tracking using Hidden Forms Field
- Sql Query Tool using Servlet
No comments:
Post a Comment