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
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 Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.