This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JSP not rendering in Spring Boot  RSS feed

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope I'm putting this in the right folder.  I have a JSP that is not rendering correctly in Spring Boot.  All I get is the word when I call the page, not the actual content.  For what it's worth, I'm retrieving data in a MongoDB database and trying to display it in the JSP.  I have verified that the data is present in the database.  I've tried multiple Google searches to try and find an answer to this.

Here is my controller code.


Here is my JSP code.


Here is my pom.xml.


Here is my application.properties.  Please note that the JSP is located directly under /WEB-INF/.
 
Greenhorn
Posts: 8
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP requires that the JavaWeb server includes an compiler for translating JSP to servlet code and Java bytecode after the Java web app has been deployed.

I think SpringBoot does not provide such a compiler.
 
Marshal
Posts: 67224
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this is very specific to Spring I've added it to the Spring forum.

I know diddly about Spring or Spring Boot, but it's pretty clear that you've mapped the URI /welcome to a method that returns the string "welcome". There's nothing there that would cause the request to hook up with your JSP that I can see.

In a servlet, you'd forward to the JSP. So I suppose you need to find out what the Spring Boot equivalent is. Hopefully, someone more Spring-savvy will weigh in...
 
Bear Bibeault
Marshal
Posts: 67224
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick web search reveals that you might just be missing a "/" in

It looks as if that might hook up to welcome.jsp.

But again, I'm just guessing...
 
Bear Bibeault
Marshal
Posts: 67224
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Roland Mueller wrote:I think SpringBoot does not provide such a compiler.


I think you are not correct.
 
Frank Serkland
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I know diddly about Spring or Spring Boot, but it's pretty clear that you've mapped the URI /welcome to a method that returns the string "welcome". There's nothing there that would cause the request to hook up with your JSP that I can see.



In other Spring web applications I've worked on, I've returned a String and the container took me to the JSP with that name.  In this case, my JSP is actually called welcome.jsp, but all I'm getting is the string welcome, not the JSP with the actual content.
 
Frank Serkland
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:A quick web search reveals that you might just be missing a "/" in



I just tried this, but it didn't work.
 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:
I know diddly about Spring or Spring Boot, but it's pretty clear that you've mapped the URI /welcome to a method that returns the string "welcome". There's nothing there that would cause the request to hook up with your JSP that I can see.



I think Mr. Bibeault may be on to something.

I wrote a tutorial on Spring MVC using Spring Boot, and for the life of me, I couldn't get Spring Boot to render a JSP. Spring Boot takes an 'opinionated approach' to enterprise development, and one of their key opinions is that JSPs stink. I simply couldn't get JSPs to work and gave up, using Spring's recommended Thymeleaf instead.

Having said that, when I've seen examples that do run, here are the dependencies I see in the POM. It does look like yours.



The only question I do have about your code is whether you have the @Controller annotation at the top of the file in which your @RequestMappings appear? I might even use @GetMapping instead of @RequestMapping just as something to try. Logically, it shouldn't matter though.
 
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Roland Mueller wrote:JSP requires that the JavaWeb server includes an compiler for translating JSP to servlet code and Java bytecode after the Java web app has been deployed.

I think SpringBoot does not provide such a compiler.



SpringBoot commonly embeds a copy of Tomcat inside the application jar. Tomcat includes the JaSPer JSP compiler. The only restriction is that since JaSPer translates the JSP to a Java Servlet, you have to be running the app under a JDK, because the Servlet requires the "javac" compiler, and JRE's don't include javac, only JDKs.

If my information is out of date, someone please correct me. There has been a push for years to make it possible to run Tomcat with only a JRE (not needing javac), but as far as I know, you still need the JDK.
 
Sheriff
Posts: 21601
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I know diddly about Spring or Spring Boot, but it's pretty clear that you've mapped the URI /welcome to a method that returns the string "welcome". There's nothing there that would cause the request to hook up with your JSP that I can see.


With Spring MVC, returning a string can trigger the rendering of the view template (JSP, Thymeleaf, ...) that the string refers to.


Frank, did you happen to annotate the class with @RestController? Because @RestController implies not just @Controller, but also @ResponseBody. This means that the "welcome" will not be treated as the name of the JSP file to render, but as the response body.
 
Frank Serkland
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:Frank, did you happen to annotate the class with @RestController? Because @RestController implies not just @Controller, but also @ResponseBody. This means that the "welcome" will not be treated as the name of the JSP file to render, but as the response body.



I just tried that and got this exception trace.
 
Frank Serkland
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Frank Serkland wrote:I just tried that and got this exception trace.



I also got this in the browser screen.

 
Rob Spoor
Sheriff
Posts: 21601
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. It seems that this method indeed causes the string "welcome" to be returned, but it's called from a different /welcome page. You need to figure out where the other one comes from.
 
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet method is mapped to "/welcome".
So forwarding to "/welcome" is the cause of your current issue (circular view path).
 
Frank Serkland
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added the @ResponseBody annotation to both the welcome and getEmployees methods.  Both methods return what they're supposed to when I run them in the Postman extension of Google Chrome, but I am now just getting "welcome" in the browser screen again, not the actual content.
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!