Session in Java: Submitting a Form

Session in Java: Submitting a Form

Last week was all about learning annotations, Java Server Pages (JSPs), and JSTL Tags. I also learned to incorporate those lessons and use session, GET, POST, and redirecting.

Annotations are a form of metadata that can be added for classes, methods, variables, parameters, and packages. For example, we use @RequestMapping to handle our paths:

JSP is about rendering our views which we do by using .jsp files (Java version of .html files) and adding some dependencies to our pom.xml file as well as properties to our application.properties file. We also need dependencies for JSTL which is the library we use to populate our templates with server data.

The pom.xml file houses all kinds of dependencies needed for Java projects and the application.properties file contains application-related properties.

Below is the code needed for JSP and JSTL to function properly:

Java templates also need to have a page rendering tag and for our JSTL we are using a tag to use c:out in order to get data from the server:

Now that our project will know where to find our templates and how to render our views, we can finally work on our template and session controllers! I applied what I learned and, for our assignment, I created the template of a simple form that grabbed the inputs and stored them in session to then pass the data to the page it redirected to.

I will show the code and also show demo video at the end:

Form template:

Submitted Results template using the c:out JSTL:

Controllers using session:

Video Demo:

This week we are putting together an entire CRUD project and I am excited to share it as soon as it is completed!