I'm trying to access a property set in my application.properties in a JSP page. This is for display purposes which sends a user to a different application from our admin page. Its not needed in code at all.
application.properties entry:
frontend.url=http://example.com/some_endpoint
In my JSP file I've tried these variations below.
<spring:eval expression="('frontend.url')" />
<spring:eval expression="'frontend.url'" />
These below throw errors
<spring:eval expression="@getProperty('frontend.url')" />
<spring:eval expression="@frontend.url" />
<spring:eval expression="@applicationProperties.getProperty('frontend.url')" />
Is there a specific syntax to use or should I just expose a request attribute from a controller?
@Value("${frontend.url}")
private String urlForDisplayPurposes;
I know the proposed method explained here enter link description here works but I really don't want an extra properties file.
For a Spring Boot JSP web application, we will need the following dependencies on the pom.xml file spring-boot-starter-web provides all the dependencies and auto-configuration we need to develop a web application in Spring Boot, including the Tomcat embedded servlet container
Inside the application properties file, we define every type of property like changing the port, database connectivity, connection to the eureka server, and many more. Now let’s see some examples for better understanding. Sometimes when you run your spring application you may encounter the following type of error
In the production environment, when a Spring Boot application is launched from a jar file, the devtools is auto disabled Create a Spring Boot controller file to map HTTP requests to JSP view files
Create a Spring Boot controller file to map HTTP requests to JSP view files The @Controller annotation indicates the annotated class is a web controller @GetMapping maps HTTP GET request for "/" (home page) and "/hello" to the hello method
Using @environment.getProperty()
should work. For example:
<spring:eval expression="@environment.getProperty('frontend.url')" var="frontendUrl" />
<a href="${frontendUrl}">Click</a>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<spring:eval expression="@environment.getProperty('myvar')" var="frontendUrl" />
and you can use "frontendUrl" in jsp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With