Spring MVC – Checkboxes

Spring MVC – Checkboxes Example ”; Previous Next The following example explains how to use Multiple Checkboxes in forms using the Spring Web MVC framework. To start with, let us have a working Eclipse IDE in place and stick to the following steps to develop a Dynamic Form based Web Application using the Spring Web Framework. Step Description 1 Create a project with a name HelloWeb under a package com.tutorialspoint as explained in the Spring MVC – Hello World chapter. 2 Create Java classes User, UserController under the com.tutorialspointpackage. 3 Create view files user.jsp, users.jsp under the jsp sub-folder. 4 The final step is to create the content of the source and configuration files and export the application as explained below. User.java package com.tutorialspoint; public class User { private String username; private String password; private String address; private boolean receivePaper; private String [] favoriteFrameworks; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public boolean isReceivePaper() { return receivePaper; } public void setReceivePaper(boolean receivePaper) { this.receivePaper = receivePaper; } public String[] getFavoriteFrameworks() { return favoriteFrameworks; } public void setFavoriteFrameworks(String[] favoriteFrameworks) { this.favoriteFrameworks = favoriteFrameworks; } } UserController.java package com.tutorialspoint; import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.ui.ModelMap; @Controller public class UserController { @RequestMapping(value = “/user”, method = RequestMethod.GET) public ModelAndView user() { User user = new User(); user.setFavoriteFrameworks((new String []{“Spring MVC”,”Struts 2″})); ModelAndView modelAndView = new ModelAndView(“user”, “command”, user); return modelAndView; } @RequestMapping(value = “/addUser”, method = RequestMethod.POST) public String addUser(@ModelAttribute(“SpringWeb”)User user, ModelMap model) { model.addAttribute(“username”, user.getUsername()); model.addAttribute(“password”, user.getPassword()); model.addAttribute(“address”, user.getAddress()); model.addAttribute(“receivePaper”, user.isReceivePaper()); model.addAttribute(“favoriteFrameworks”, user.getFavoriteFrameworks()); return “users”; } @ModelAttribute(“webFrameworkList”) public List<String> getWebFrameworkList() { List<String> webFrameworkList = new ArrayList<String>(); webFrameworkList.add(“Spring MVC”); webFrameworkList.add(“Struts 1”); webFrameworkList.add(“Struts 2”); webFrameworkList.add(“Apache Wicket”); return webFrameworkList; } } Here, for the first service method user(), we have passed a blank User object in the ModelAndView object with name “command”, because the spring framework expects an object with name “command”, if you are using <form:form> tags in your JSP file. So, when the user() method is called, it returns the user.jsp view. The second service method addUser() will be called against a POST method on the HelloWeb/addUser URL. You will prepare your model object based on the submitted information. Finally, the “users” view will be returned from the service method, which will result in rendering the users.jsp user.jsp <%@taglib uri = “http://www.springframework.org/tags/form” prefix = “form”%> <html> <head> <title>Spring MVC Form Handling</title> </head> <body> <h2>User Information</h2> <form:form method = “POST” action = “/HelloWeb/addUser”> <table> <tr> <td><form:label path = “username”>User Name</form:label></td> <td><form:input path = “username” /></td> </tr> <tr> <td><form:label path = “password”>Age</form:label></td> <td><form:password path = “password” /></td> </tr> <tr> <td><form:label path = “address”>Address</form:label></td> <td><form:textarea path = “address” rows = “5” cols = “30” /></td> </tr> <tr> <td><form:label path = “receivePaper”>Subscribe Newsletter</form:label></td> <td><form:checkbox path = “receivePaper” /></td> </tr> <tr> <td><form:label path = “favoriteFrameworks”>Favorite Web Frameworks</form:label></td> <td><form:checkboxes items = “${webFrameworkList}” path = “favoriteFrameworks” /></td> </tr> <tr> <td colspan = “2”> <input type = “submit” value = “Submit”/> </td> </tr> </table> </form:form> </body> </html> Here, we are using <form:checkboxes /> tag to render HTML checkboxes. <form:checkboxes items = “${webFrameworkList}” path = “favoriteFrameworks” /> It will render following HTML content. <span> <input id = “favoriteFrameworks1” name = “favoriteFrameworks” type = “checkbox” value = “Spring MVC” checked = “checked”/> <label for = “favoriteFrameworks1”>Spring MVC</label> </span> <span> <input id = “favoriteFrameworks2” name = “favoriteFrameworks” type = “checkbox” value = “Struts 1″/> <label for = “favoriteFrameworks2”>Struts 1</label> </span> <span> <input id = “favoriteFrameworks3” name = “favoriteFrameworks” type = “checkbox” value = “Struts 2” checked = “checked”/> <label for = “favoriteFrameworks3”>Struts 2</label> </span> <span> <input id = “favoriteFrameworks4” name = “favoriteFrameworks” type = “checkbox” value = “Apache Wicket”/> <label for = “favoriteFrameworks4”>Apache Wicket</label> </span> <input type = “hidden” name = “_favoriteFrameworks” value = “on”/> users.jsp <%@taglib uri = “http://www.springframework.org/tags/form” prefix = “form”%> <html> <head> <title>Spring MVC Form Handling</title> </head> <body> <h2>Submitted User Information</h2> <table> <tr> <td>Username</td> <td>${username}</td> </tr> <tr> <td>Password</td> <td>${password}</td> </tr> <tr> <td>Address</td> <td>${address}</td> </tr> <tr> <td>Subscribed to Newsletter</td> <td>${receivePaper}</td> </tr> <tr> <td>Favorite Web Frameworks</td> <td> <% String[] favoriteFrameworks = (String[])request.getAttribute(“favoriteFrameworks”); for(String framework: favoriteFrameworks) { out.println(framework); } %></td> </tr> </table> </body> </html> Once you are done with creating source and configuration files, export your application. Right click on your application, use Export → WAR File option and save your HelloWeb.war file in Tomcat”s webapps folder. Now, start the Tomcat server and make sure you are able to access other webpages from webapps folder using a standard browser. Try a URL http://localhost:8080/HelloWeb/user and we will see the following screen if everything is fine with the Spring Web Application. After submitting the required information, click on the submit button to submit the form. We will see the following screen, if everything is fine with your Spring Web Application. Print Page Previous Next Advertisements ”;

Spring MVC – Textarea

Spring MVC – TextArea Example ”; Previous Next The following example explains how to use TextArea in forms using the Spring Web MVC framework. To begin with, let us have a working Eclipse IDE in place and follow the subsequent steps to develop a Dynamic Form based Web Application using the Spring Web Framework. Step Description 1 Create a project with a name HelloWeb under a package com.tutorialspoint as explained in the Spring MVC − Hello World chapter. 2 Create Java classes User, UserController under the com.tutorialspointpackage. 3 Create view files user.jsp, users.jsp under jsp sub-folder. 4 The final step is to create the content of the source and configuration files and export the application as explained below. User.java package com.tutorialspoint; public class User { private String username; private String password; private String address; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } } UserController.java package com.tutorialspoint; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.ui.ModelMap; @Controller public class UserController { @RequestMapping(value = “/user”, method = RequestMethod.GET) public ModelAndView user() { return new ModelAndView(“user”, “command”, new User()); } @RequestMapping(value = “/addUser”, method = RequestMethod.POST) public String addUser(@ModelAttribute(“SpringWeb”)User user, ModelMap model) { model.addAttribute(“username”, user.getUsername()); model.addAttribute(“password”, user.getPassword()); model.addAttribute(“address”, user.getAddress()); return “users”; } } Here, for the first service method user(), we have passed a blank User object in the ModelAndView object with name “command”, because the spring framework expects an object with name “command”, if you are using <form:form> tags in your JSP file. So, when the user() method is called, it returns the user.jsp view. The second service method addUser() will be called against a POST method on the HelloWeb/addUser URL. You will prepare your model object based on the submitted information. Finally, the “users” view will be returned from the service method, which will result in rendering the users.jsp. user.jsp <%@taglib uri = “http://www.springframework.org/tags/form” prefix = “form”%> <html> <head> <title>Spring MVC Form Handling</title> </head> <body> <h2>User Information</h2> <form:form method = “POST” action = “/HelloWeb/addUser”> <table> <tr> <td><form:label path = “username”>User Name</form:label></td> <td><form:input path = “username” /></td> </tr> <tr> <td><form:label path = “password”>Age</form:label></td> <td><form:password path = “password” /></td> </tr> <tr> <td><form:label path = “address”>Address</form:label></td> <td><form:textarea path = “address” rows = “5” cols = “30” /></td> </tr> <tr> <td colspan = “2”> <input type = “submit” value = “Submit”/> </td> </tr> </table> </form:form> </body> </html> Here, we are using <form:textarea /> tag to render a HTML textarea box. For example − <form:textarea path = “address” rows = “5” cols = “30” /> It will render the following HTML content. <textarea id = “address” name = “address” rows = “5” cols = “30”></textarea> users.jsp <%@taglib uri = “http://www.springframework.org/tags/form” prefix = “form”%> <html> <head> <title>Spring MVC Form Handling</title> </head> <body> <h2>Submitted User Information</h2> <table> <tr> <td>Username</td> <td>${username}</td> </tr> <tr> <td>Password</td> <td>${password}</td> </tr> <tr> <td>Address</td> <td>${address}</td> </tr> </table> </body> </html> Once you are done with creating source and configuration files, export your application. Right click on your application, use Export → WAR File option and save your HelloWeb.war file in Tomcat”s webapps folder. Now, start your Tomcat server and make sure you are able to access other webpages from webapps folder using a standard browser. Try a URL –http://localhost:8080/HelloWeb/user and we will see the following screen if everything is fine with the Spring Web Application. After submitting the required information, click on the submit button to submit the form. We will see the following screen, if everything is fine with the Spring Web Application. Print Page Previous Next Advertisements ”;

Spring Security – Quick Guide

Spring Security – Quick Guide ”; Previous Next Spring Security – Form Login with Database Contents Introduction and Overview Basic components of Spring Security AuthenticationFilter AuthenticationManager AuthenticationProvider UserDetailsService PasswordEncoder Spring Security Context Form Login Login with a Database Login Attempts Limit Getting Started (Practical Guide) Introduction and Overview In addition to providing various inbuilt authentication and authorization options, Spring Security allows us to customize our authentication process as much as we want. Starting from a custom login page to our very own customized authentication providers and authentication filters, we can pretty much customize every aspect of the authentication process. We can define our own authentication process which can range from basic authentication using a username and a password to a complex one such as two-factor authentication using tokens and OTP’s. Also, we can use various databases – both relational and non-relational, use various password encoders, lock malicious users out of their accounts, and so on. Today, we are going to discuss three such customizations, namely – custom form-login, a database provided authentication, and limiting login attempts. Though these are pretty basic use-cases, yet these still will let us have a closer look into Spring Security’s authentication and authorization process. We are also going to set up a registration page through which the users will be able to register themselves with our application. First of all, let’s take a look at the architecture of Spring Security. It starts with servlet filters. These filters intercept requests, perform operations on them, and then pass the requests on to next filters in the filter chain or request handlers or block them if they do not meet certain conditions. It is during this process that Spring Security can authenticate requests and perform various authentication checks on the requests. It can also prevent unauthenticated or malicious requests from accessing our protected resources by not allowing them to pass through. Thus our application and resources stay protected. Components of Spring Security Architecture The basic components of Spring Security, as we can see in the above diagram are given below. We shall discuss them briefly as we go along. We shall also discuss their roles in the authentication and authorization process. AuthenticationFilter This is the filter that intercepts requests and attempts to authenticate it. In Spring Security, it converts the request to an Authentication Object and delegates the authentication to the AuthenticationManager. AuthenticationManager It is the main strategy interface for authentication. It uses the lone method authenticate() to authenticate the request. The authenticate() method performs the authentication and returns an Authentication Object on successful authentication or throw an AuthenticationException in case of authentication failure. If the method can’t decide, it will return null. The process of authentication in this process is delegated to the AuthenticationProvider which we will discuss next. AuthenticationProvider The AuthenticationManager is implemented by the ProviderManager which delegates the process to one or more AuthenticationProvider instances. Any class implementing the AuthenticationProvider interface must implement the two methods – authenticate() and supports(). First, let us talk about the supports() method. It is used to check if the particular authentication type is supported by our AuthenticationProvider implementation class. If it is supported it returns true or else false. Next, the authenticate() method. Here is where the authentication occurs. If the authentication type is supported, the process of authentication is started. Here is this class can use the loadUserByUsername() method of the UserDetailsService implementation. If the user is not found, it can throw a UsernameNotFoundException. On the other hand, if the user is found, then the authentication details of the user are used to authenticate the user. For example, in the basic authentication scenario, the password provided by the user may be checked with the password in the database. If they are found to match with each other, it is a success scenario. Then we can return an Authentication object from this method which will be stored in the Security Context, which we will discuss later. UserDetailsService It is one of the core interfaces of Spring Security. The authentication of any request mostly depends on the implementation of the UserDetailsService interface. It is most commonly used in database backed authentication to retrieve user data. The data is retrieved with the implementation of the lone loadUserByUsername() method where we can provide our logic to fetch the user details for a user. The method will throw a UsernameNotFoundException if the user is not found. PasswordEncoder Until Spring Security 4, the use of PasswordEncoder was optional. The user could store plain text passwords using in-memory authentication. But Spring Security 5 has mandated the use of PasswordEncoder to store passwords. This encodes the user’s password using one its many implementations. The most common of its implementations is the BCryptPasswordEncoder. Also, we can use an instance of the NoOpPasswordEncoder for our development purposes. It will allow passwords to be stored in plain text. But it is not supposed to be used for production or real-world applications. Spring Security Context This is where the details of the currently authenticated user are stored on successful authentication. The authentication object is then available throughout the application for the session. So, if we need the username or any other user details, we need to get the SecurityContext first. This is done with the SecurityContextHolder, a helper class, which provides access to the security context. We can use the setAuthentication() and getAuthentication() methods for storing and retrieving the user details respectively. Moving on, let’s now discuss the three custom implementations we are going to use for our application. Form Login When we add Spring Security to an existing Spring application it adds a login form and sets up a dummy user. This is Spring Security in auto-configuration mode. In this mode, it

Spring Boot CLI – Useful Resources

Spring Boot CLI – Useful Resources ”; Previous Next The following resources contain additional information on Spring Boot CLI. Please use them to get more in-depth knowledge on this topic. Useful Links on Spring Boot CLI Spring Boot CLI – Spring Boot CLI Official Home page. Useful Books on Spring Boot CLI To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;

Spring Boot CLI – Default Statements

Spring Boot CLI – Default Statements ”; Previous Next Default Imports Spring CLI automatically imports many libraries by default so that explicit imports are not required. Consider the following groovy script. @RestController class FirstApplication { @RequestMapping(“/”) String welcome() { “Welcome to TutorialsPoint.Com” } } Here import for @RestController, @RequestMapping annotations are already included by default by Spring Boot. We”re not even require to use fully-qualified names. You can check by running the application. Type the following command E:/Test/> spring run FirstApplication.groovy You can see the following output on console. . ____ _ __ _ _ /\ / ___”_ __ _ _(_)_ __ __ _ ( ( )___ | ”_ | ”_| | ”_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ” |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.6.3) 2022-02-03 11:29:01.177 INFO 10668 — [ runner-0] o.s.boot.SpringApplication : Starting application using Java 11.0.11 on DESKTOP-86KD9FC with PID 10668 (started by intel in F:Test) 2022-02-03 11:29:01.187 INFO 10668 — [ runner-0] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default 2022-02-03 11:29:03.555 INFO 10668 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-02-03 11:29:03.591 INFO 10668 — [ runner-0] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-02-03 11:29:03.592 INFO 10668 — [ runner-0] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2022-02-03 11:29:03.659 INFO 10668 — [ runner-0] org.apache.catalina.loader.WebappLoader : Unknown class loader [org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@8646db9] of class [class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader] 2022-02-03 11:29:03.735 INFO 10668 — [ runner-0] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-02-03 11:29:03.736 INFO 10668 — [ runner-0] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2107 ms 2022-02-03 11:29:04.945 INFO 10668 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ”” 2022-02-03 11:29:04.968 INFO 10668 — [ runner-0] o.s.boot.SpringApplication : Started application in 4.811 seconds (JVM running for 8.805) Automatic Main Method We are not required to create standard main method for groovy script to initialize a spring application. It is automatically created for spring boot application. Print Page Previous Next Advertisements ”;

Spring Boot CLI – “grab” Co-Ordination Deduction

“grab” Co-ordinates Deduction ”; Previous Next We can specify a dependency using @Grab annotation even without specifying group or version. For example, @Grab(”antlr”) Now Spring Boot CLI will download 2.7.7 version of antlr as it is present in Spring Boot”s default dependency metadata for 2.6.3 version. Spring Boot maintains all dependency versions by default which are provided in its CLI, Maven dependency management and Gradle plugin. Whenever we declare a dependency of any of those artifacts present in efault dependency metadata without declaring a version, the version listed in its table will be used. Following table shows all the dependencies and their versions included in the default metadata for Spring Boot CLI 2.6.3 version. Group Id Artifact Id Version antlr antlr 2.7.7 ch.qos.logback logback-access 1.2.10 ch.qos.logback logback-classic 1.2.10 ch.qos.logback logback-core 1.2.10 com.atomikos transactions-jdbc 4.0.6 com.atomikos transactions-jms 4.0.6 com.atomikos transactions-jta 4.0.6 com.couchbase.client java-client 3.2.4 com.datastax.oss java-driver-core 4.13.0 com.datastax.oss java-driver-core-shaded 4.13.0 com.datastax.oss java-driver-mapper-processor 4.13.0 com.datastax.oss java-driver-mapper-runtime 4.13.0 com.datastax.oss java-driver-metrics-micrometer 4.13.0 com.datastax.oss java-driver-metrics-microprofile 4.13.0 com.datastax.oss java-driver-query-builder 4.13.0 com.datastax.oss java-driver-shaded-guava 25.1-jre-graal-sub-1 com.datastax.oss java-driver-test-infra 4.13.0 com.datastax.oss native-protocol 1.5.0 com.fasterxml classmate 1.5.1 com.fasterxml.jackson.core jackson-annotations 2.13.1 com.fasterxml.jackson.core jackson-core 2.13.1 com.fasterxml.jackson.core jackson-databind 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-avro 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-cbor 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-csv 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-ion 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-properties 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-protobuf 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-smile 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-toml 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-xml 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-yaml 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-eclipse-collections 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-guava 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-hibernate4 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-hibernate5 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-hibernate5-jakarta 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-hppc 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jakarta-jsonp 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jaxrs 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jdk8 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-joda 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-joda-money 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-json-org 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jsr310 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jsr353 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-pcollections 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-base 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-cbor-provider 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-json-provider 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-smile-provider 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-xml-provider 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-yaml-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-base 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-cbor-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-smile-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-xml-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-yaml-provider 2.13.1 com.fasterxml.jackson.jr jackson-jr-all 2.13.1 com.fasterxml.jackson.jr jackson-jr-annotation-support 2.13.1 com.fasterxml.jackson.jr jackson-jr-objects 2.13.1 com.fasterxml.jackson.jr jackson-jr-retrofit2 2.13.1 com.fasterxml.jackson.jr jackson-jr-stree 2.13.1 com.fasterxml.jackson.module jackson-module-afterburner 2.13.1 com.fasterxml.jackson.module jackson-module-blackbird 2.13.1 com.fasterxml.jackson.module jackson-module-guice 2.13.1 com.fasterxml.jackson.module jackson-module-jakarta-xmlbind-annotations 2.13.1 com.fasterxml.jackson.module jackson-module-jaxb-annotations 2.13.1 com.fasterxml.jackson.module jackson-module-jsonSchema 2.13.1 com.fasterxml.jackson.module jackson-module-kotlin 2.13.1 com.fasterxml.jackson.module jackson-module-mrbean 2.13.1 com.fasterxml.jackson.module jackson-module-no-ctor-deser 2.13.1 com.fasterxml.jackson.module jackson-module-osgi 2.13.1 com.fasterxml.jackson.module jackson-module-parameter-names 2.13.1 com.fasterxml.jackson.module jackson-module-paranamer 2.13.1 com.fasterxml.jackson.module jackson-module-scala_2.11 2.13.1 com.fasterxml.jackson.module jackson-module-scala_2.12 2.13.1 com.fasterxml.jackson.module jackson-module-scala_2.13 2.13.1 com.fasterxml.jackson.module jackson-module-scala_3 2.13.1 com.github.ben-manes.caffeine caffeine 2.9.3 com.github.ben-manes.caffeine guava 2.9.3 com.github.ben-manes.caffeine jcache 2.9.3 com.github.ben-manes.caffeine simulator 2.9.3 com.github.mxab.thymeleaf.extras thymeleaf-extras-data-attribute 2.0.1 com.google.appengine appengine-api-1.0-sdk 1.9.93 com.google.cloud cloud-spanner-r2dbc 1.1.0 com.google.code.gson gson 2.8.9 com.h2database h2 1.4.200 com.hazelcast hazelcast 4.2.4 com.hazelcast hazelcast-hibernate52 2.2.1 com.hazelcast hazelcast-hibernate53 2.2.1 com.hazelcast hazelcast-spring 4.2.4 com.ibm.db2 jcc 11.5.7.0 com.jayway.jsonpath json-path 2.6.0 com.jayway.jsonpath json-path-assert 2.6.0 com.microsoft.sqlserver mssql-jdbc 9.4.1.jre8 com.oracle.database.ha ons 21.3.0.0 com.oracle.database.ha simplefan 21.3.0.0 com.oracle.database.jdbc ojdbc11 21.3.0.0 com.oracle.database.jdbc ojdbc11-production 21.3.0.0 com.oracle.database.jdbc ojdbc8 21.3.0.0 com.oracle.database.jdbc ojdbc8-production 21.3.0.0 com.oracle.database.jdbc rsi 21.3.0.0 com.oracle.database.jdbc ucp 21.3.0.0 com.oracle.database.jdbc ucp11 21.3.0.0 com.oracle.database.jdbc.debug ojdbc11-debug 21.3.0.0 com.oracle.database.jdbc.debug ojdbc11-observability-debug 21.3.0.0 com.oracle.database.jdbc.debug ojdbc11_g 21.3.0.0 com.oracle.database.jdbc.debug ojdbc11dms_g 21.3.0.0 com.oracle.database.jdbc.debug ojdbc8-debug 21.3.0.0 com.oracle.database.jdbc.debug ojdbc8-observability-debug 21.3.0.0 com.oracle.database.jdbc.debug ojdbc8_g 21.3.0.0 com.oracle.database.jdbc.debug ojdbc8dms_g 21.3.0.0 com.oracle.database.nls orai18n 21.3.0.0 com.oracle.database.observability dms 21.3.0.0 com.oracle.database.observability ojdbc11-observability 21.3.0.0 com.oracle.database.observability ojdbc11dms 21.3.0.0 com.oracle.database.observability ojdbc8-observability 21.3.0.0 com.oracle.database.observability ojdbc8dms 21.3.0.0 com.oracle.database.r2dbc oracle-r2dbc 0.1.0 com.oracle.database.security oraclepki 21.3.0.0 com.oracle.database.security osdt_cert 21.3.0.0 com.oracle.database.security osdt_core 21.3.0.0 com.oracle.database.xml xdb 21.3.0.0 com.oracle.database.xml xmlparserv2 21.3.0.0 com.querydsl querydsl-apt 5.0.0 com.querydsl querydsl-codegen 5.0.0 com.querydsl querydsl-codegen-utils 5.0.0 com.querydsl querydsl-collections 5.0.0 com.querydsl querydsl-core 5.0.0 com.querydsl querydsl-guava 5.0.0 com.querydsl querydsl-hibernate-search 5.0.0 com.querydsl querydsl-jdo 5.0.0 com.querydsl querydsl-jpa 5.0.0 com.querydsl querydsl-jpa-codegen 5.0.0 com.querydsl querydsl-kotlin 5.0.0 com.querydsl querydsl-kotlin-codegen 5.0.0 com.querydsl querydsl-lucene3 5.0.0 com.querydsl querydsl-lucene4 5.0.0 com.querydsl querydsl-lucene5 5.0.0 com.querydsl querydsl-mongodb 5.0.0 com.querydsl querydsl-scala 5.0.0 com.querydsl querydsl-spatial 5.0.0 com.querydsl querydsl-sql 5.0.0 com.querydsl querydsl-sql-codegen 5.0.0 com.querydsl querydsl-sql-spatial 5.0.0 com.querydsl querydsl-sql-spring 5.0.0 com.rabbitmq amqp-client 5.13.1 com.rabbitmq stream-client 0.4.0 com.samskivert jmustache 1.15 com.sendgrid sendgrid-java 4.7.6 com.squareup.okhttp3 logging-interceptor 3.14.9 com.squareup.okhttp3 mockwebserver 3.14.9 com.squareup.okhttp3 okcurl 3.14.9 com.squareup.okhttp3 okhttp 3.14.9 com.squareup.okhttp3 okhttp-dnsoverhttps 3.14.9 com.squareup.okhttp3 okhttp-sse 3.14.9 com.squareup.okhttp3 okhttp-testing-support 3.14.9 com.squareup.okhttp3 okhttp-tls 3.14.9 com.squareup.okhttp3 okhttp-urlconnection 3.14.9 com.sun.activation jakarta.activation 1.2.2 com.sun.mail jakarta.mail 1.6.7 com.sun.xml.messaging.saaj saaj-impl 1.5.3 com.unboundid unboundid-ldapsdk 4.0.14 com.zaxxer HikariCP 4.0.3 commons-codec commons-codec 1.15 commons-pool commons-pool 1.6 de.flapdoodle.embed de.flapdoodle.embed.mongo 3.0.0 dev.miku r2dbc-mysql 0.8.2.RELEASE io.dropwizard.metrics metrics-annotation 4.2.7 io.dropwizard.metrics metrics-caffeine 4.2.7 io.dropwizard.metrics metrics-caffeine3 4.2.7 io.dropwizard.metrics metrics-collectd 4.2.7 io.dropwizard.metrics metrics-core 4.2.7 io.dropwizard.metrics metrics-ehcache 4.2.7 io.dropwizard.metrics metrics-graphite 4.2.7 io.dropwizard.metrics metrics-healthchecks 4.2.7 io.dropwizard.metrics metrics-httpasyncclient 4.2.7 io.dropwizard.metrics metrics-httpclient 4.2.7 io.dropwizard.metrics metrics-httpclient5 4.2.7 io.dropwizard.metrics metrics-jakarta-servlet 4.2.7 io.dropwizard.metrics metrics-jakarta-servlets 4.2.7 io.dropwizard.metrics metrics-jcache 4.2.7 io.dropwizard.metrics metrics-jdbi 4.2.7 io.dropwizard.metrics metrics-jdbi3 4.2.7 io.dropwizard.metrics metrics-jersey2 4.2.7 io.dropwizard.metrics metrics-jersey3 4.2.7 io.dropwizard.metrics metrics-jetty10 4.2.7 io.dropwizard.metrics metrics-jetty11 4.2.7 io.dropwizard.metrics metrics-jetty9 4.2.7 io.dropwizard.metrics metrics-jmx 4.2.7 io.dropwizard.metrics metrics-json 4.2.7 io.dropwizard.metrics metrics-jvm 4.2.7 io.dropwizard.metrics metrics-log4j2 4.2.7 io.dropwizard.metrics metrics-logback 4.2.7 io.dropwizard.metrics metrics-servlet 4.2.7 io.dropwizard.metrics metrics-servlets 4.2.7 io.lettuce lettuce-core 6.1.6.RELEASE io.micrometer micrometer-core 1.8.2 io.micrometer micrometer-jersey2 1.8.2 io.micrometer micrometer-registry-appoptics 1.8.2 io.micrometer micrometer-registry-atlas 1.8.2 io.micrometer micrometer-registry-azure-monitor 1.8.2 io.micrometer micrometer-registry-cloudwatch 1.8.2 io.micrometer micrometer-registry-cloudwatch2 1.8.2 io.micrometer micrometer-registry-datadog 1.8.2 io.micrometer micrometer-registry-dynatrace 1.8.2 io.micrometer micrometer-registry-elastic 1.8.2 io.micrometer micrometer-registry-ganglia 1.8.2 io.micrometer micrometer-registry-graphite 1.8.2 io.micrometer micrometer-registry-health 1.8.2 io.micrometer micrometer-registry-humio 1.8.2 io.micrometer micrometer-registry-influx 1.8.2 io.micrometer micrometer-registry-jmx 1.8.2 io.micrometer micrometer-registry-kairos 1.8.2

Spring Boot CLI – Discussion

Discuss Spring Boot CLI ”; Previous Next Spring Boot CLI is a command line tool, which is used for a quick start with Spring. It allows running Groovy scripts. Groovy scripts are similar to Java code without any boilerplate code. Spring CLI helps to bootstrap a new project or write custom command for it. Print Page Previous Next Advertisements ”;

Spring MVC – Generate Excel

Spring MVC – Generate Excel Example ”; Previous Next The following example shows how to generate Excel using the Spring Web MVC Framework. To begin with, let us have a working Eclipse IDE in place and stick to the following steps to develop a Dynamic Form based Web Application using the Spring Web Framework. Step Description 1 Create a project with a name TestWeb under a package com.tutorialspoint as explained in the Spring MVC – Hello World chapter. 2 Create Java classes UserExcelView and ExcelController under the com.tutorialspoint package. 3 Download the Apache POI library Apache POI from the maven repository page. Put it in your CLASSPATH. 4 The final step is to create the content of the source and configuration files and export the application as explained below. ExcelController.java package com.tutorialspoint; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; public class ExcelController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { //user data Map<String,String> userData = new HashMap<String,String>(); userData.put(“1”, “Mahesh”); userData.put(“2”, “Suresh”); userData.put(“3”, “Ramesh”); userData.put(“4”, “Naresh”); return new ModelAndView(“UserSummary”,”userData”,userData); } } UserExcelView.java package com.tutorialspoint; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.springframework.web.servlet.view.document.AbstractExcelView; public class UserExcelView extends AbstractExcelView { @Override protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String,String> userData = (Map<String,String>) model.get(“userData”); //create a wordsheet HSSFSheet sheet = workbook.createSheet(“User Report”); HSSFRow header = sheet.createRow(0); header.createCell(0).setCellValue(“Roll No”); header.createCell(1).setCellValue(“Name”); int rowNum = 1; for (Map.Entry<String, String> entry : userData.entrySet()) { //create the row data HSSFRow row = sheet.createRow(rowNum++); row.createCell(0).setCellValue(entry.getKey()); row.createCell(1).setCellValue(entry.getValue()); } } } TestWeb-servlet.xml <beans xmlns = “http://www.springframework.org/schema/beans” xmlns:context = “http://www.springframework.org/schema/context” xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance” xmlns:mvc = “http://www.springframework.org/schema/mvc” xsi:schemaLocation = ” http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd”> <bean class = “org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping” /> <bean class = “com.tutorialspoint.ExcelController” /> <bean class = “org.springframework.web.servlet.view.XmlViewResolver”> <property name = “location”> <value>/WEB-INF/views.xml</value> </property> </bean> </beans> views.xml <beans xmlns = “http://www.springframework.org/schema/beans” xmlns:context = “http://www.springframework.org/schema/context” xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation = ” http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd”> <bean id = “UserSummary” class = “com.tutorialspoint.UserExcelView”></bean> </beans> Here, we have created an ExcelController and an ExcelView. Apache POI library deals with Microsoft Office file formats and will convert the data to an excel document. Once you are done with creating source and configuration files, export your application. Right click on your application, use Export → WAR File option and save the TestWeb.war file in Tomcat”s webapps folder. Now, start the Tomcat server and make sure you are able to access other webpages from the webapps folder using a standard browser. Try a URL − http://localhost:8080/TestWeb/excel and we will see the following screen. Print Page Previous Next Advertisements ”;

Spring Boot CLI – Quick Guide

Spring Boot CLI – Quick Guide ”; Previous Next Spring Boot CLI – Overview The Spring Boot CLI is a Command Line Interface for Spring Boot. It can be used for a quick start with Spring. It can run Groovy scripts which means that a developer need not write boilerplate code; all that is needed is focus on business logic. Spring Boot CLI is the fastest way to create a Spring-based application. Features In this section, we will look at the different features of Spring Boot CL − It provides an interface to run and test Spring Boot Application from command prompt. It internally use Spring Boot Starter and Spring Boot AutoConfigurate components in order to resolve all dependencies and executes the application. It contains Groovy compiler and Grape Dependency Manager. It supports Groovy Scripts without external Groovy installation. It adds Spring Boot defaults and resolve all dependencies automatically. Spring Boot CLI – Environment Setup Spring is a Java-based framework; hence, we need to set up JDK first. Following are the steps needed to setup Spring Boot CLI along with JDK installation. Step 1 Setup Java Development Kit (JDK) You can download the latest version of SDK from Oracle”s Java site − Java SE Downloads. You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively. If you are running Windows and have installed the JDK in C:jdk-11.0.11, you would have to put the following line in your C:autoexec.bat file. set PATH=C:jdk-11.0.11;%PATH% set JAVA_HOME=C:jdk-11.0.11 Alternatively, on Windows NT/2000/XP, you will have to right-click on My Computer, select Properties → Advanced → Environment Variables. Then, you will have to update the PATH value and click the OK button. On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk-11.0.11 and you use the C shell, you will have to put the following into your .cshrc file. setenv PATH /usr/local/jdk-11.0.11/bin:$PATH setenv JAVA_HOME /usr/local/jdk-11.0.11 Step 2 – Install Spring Boot CLI You can download the latest version of Spring Boot CLI API as ZIP archive from https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/. Once you download the installation, unpack the zip distribution into a convenient location. For example, in E:Testspring-boot-cli-2.6.3 on Windows, or /usr/local/spring-boot-cli-2.6.3 on Linux/Unix. Make sure you set your CLASSPATH variable on this directory properly otherwise you will face a problem while running your application. Or set the path in command prompt temporarily to run the spring boot application as shown below − E:/Test/> set path=E:Testspring-boot-cli-2.6.3-binspring-2.6.3bin;%PATH% Step 3 – Verify installation Run the following command on command prompt to verify the installation − E:/Test/> spring –version It should print the following output confirming the successful installation − Spring CLI v2.6.3 Spring Boot CLI – Hello World Example In this example, we”ll create a Spring Boot + MVC + Rest based Web application. Step 1: Create source Folder Create a folder FirstApplication in E:Test folder. Step 2: Create Source File Create FirstApplication.groovy file in E:Test folder with following source code. @RestController class FirstApplication { @RequestMapping(“/”) String welcome() { “Welcome to TutorialsPoint.Com” } } Step 3: Run the application Type the following command E:/Test/> spring run FirstApplication.groovy Now Spring Boot CLI will come into action, download required dependencies, run the embedded tomcat, deploy the application and start it. You can see the following output on console. E:Test>spring run FirstApplication.groovy Resolving dependencies…………………………. . ____ _ __ _ _ /\ / ___”_ __ _ _(_)_ __ __ _ ( ( )___ | ”_ | ”_| | ”_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ” |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.6.3) 2022-02-03 11:12:42.683 INFO 6956 — [ runner-0] o.s.boot.SpringApplication : Starting application using Java 11.0.11 on DESKTOP-86KD9FC with PID 6956 (started by intel in F:Test) 2022-02-03 11:12:42.710 INFO 6956 — [ runner-0] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default 2022-02-03 11:12:45.110 INFO 6956 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-02-03 11:12:45.138 INFO 6956 — [ runner-0] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-02-03 11:12:45.139 INFO 6956 — [ runner-0] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2022-02-03 11:12:45.229 INFO 6956 — [ runner-0] org.apache.catalina.loader.WebappLoader : Unknown class loader [org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@8646db9] of class [class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader] 2022-02-03 11:12:45.333 INFO 6956 — [ runner-0] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-02-03 11:12:45.333 INFO 6956 — [ runner-0] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2124 ms 2022-02-03 11:12:46.901 INFO 6956 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ”” 2022-02-03 11:12:46.930 INFO 6956 — [ runner-0] o.s.boot.SpringApplication : Started application in 5.416 seconds (JVM running for 49.049) 2022-02-03 11:13:48.910 INFO 6956 — [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ”dispatcherServlet” 2022-02-03 11:13:48.912 INFO 6956 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ”dispatcherServlet” 2022-02-03 11:13:48.915 INFO 6956 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms Step 4: Browse the application in Browser Our spring based rest application is now ready. Open url as “http://localhost:8080/” and you will see the following output. Welcome to TutorialsPoint.Com Points to consider Following actions are taken by Spring CLI. All dependency JARs are downloaded for the first time only. Spring CLI automatically detects which dependency JARs are to be downloaded based on the classes and annotations used in code. Finally it compiles the code, deploy the war on a embedded tomcat, start embedded tomcat server on the default port 8080. “grab”

Example – CheckBoxes

Swing Examples – CheckBoxes ”; Previous Next Learn how to play with CheckBoxes in Swing UI programming. Here are most commonly used examples − How to create and use Check box in a Java Swing application? How to create and use Radio buttons in a Java Swing application? How to make a radio button group in a Java Swing application? Print Page Previous Next Advertisements ”;