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.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- How to display search result of another page on same page using ajax in JSP?
- Spring MVC with JSP View
- getParameter() - Passing data from client to JSP
- getAttribute() - Passing data from Server to JSP
- Introduction to JSP
- Exception handling in JSP
- Environment setup for JSP
- Life cycle of JSP
- Difference between Servlet and JSP
- Directives in JSP
- JSP | Declaration Tag
- JSP | ScriptletTag
- JSP | Expression tag
- JSP | Implicit Objects - request and response
- JSTL | JSP Standard Tag Library
- Difference between JSP and ASP
- JSP Access Model
- Classes of JSP API
- Difference Between JSP and PHP
- What is JSP Filters?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.