Introduction to JSP : JSP(Java Server Page) is a server-side technology, used for developing webpages that support dynamic content. It enables the separation of dynamic and static content, thereby reducing development complexity. Developers are thus, armed with the power to insert java code in HTML pages by employing special JSP tags most of which start with <% and end with %>. It may further be noted here that JSP’s are built on top of Java Servlet API and also allow tags that begin with
and end with
Tags thus determine how the code within them will behave.
Here the power of JSP will be harnessed in order to Validate a user from his username and password. The user will initially be entering his username and password in a JSP form provided. The data will then be passed to another JSP to get the java bean object from the given scope or create a new object of java bean. The bean properties will then be set using the form data and verified using another java class. Finally, the result of verification will be displayed.
In this, the JSP Action tags are used to achieve the above purpose. JSP tags are specifically used during request processing. The tags used here will be as follows :
jsp:useBean: It will be used to create the java bean and instantiate it.
jsp:setProperty: It will be used to set the property of the created bean, using the form data.
jsp:getProperty: It will be used to display the details entered.
It may be noted here that, all actions tags use the id attribute to uniquely identify an action element and refer to it inside the JSP page.
The program has been tested on Netbeans IDE 8.1 using Apache Tomcat as the application server.
Steps to Validate a User:
- We click the link on index.html page to deploy the application.
- We are then presented with a form, where we enter username and password and click submit.
- The JSP gets automatically called and it returns the data entered in the form and the result of Validation.
Form to accept username and password : login.jsp
JSP to accept form data and verify a user : acceptuser.jsp
The ValidateUser.java class
Next on clicking ‘SUBMIT’ button following page is generated.
- How to read a Matrix from user in Java?
- How to create a user defined javap tool?
- User-defined Custom Exception in Java
- Swap two Strings without using third user defined variable in Java
- Using TreeMap to sort User-defined Objects in Java
- How to create a Java HashMap of user defined class type?
- Difference Between Daemon Threads and User Threads In Java
- Java Program for Program to calculate area of a Tetrahedron
- Java Program for Program to find area of a circle
- Java Program for Program for array rotation
- Program to calculate the value of nPr
- Java Program for Cutting a Rod | DP-13
- Java Program to take Screenshots
- Program to find the sum of the series (1/a + 2/a^2 + 3/a^3 + ... + n/a^n)
- Program to Add Two Complex Numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.