This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin 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

Convert servlet to controller and html  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have been playing around with servlets and spring mvc a bit and have been trying to figure out how to convert a servlet to a controller and html. I was able to get my controller working where it would be able to post the html page. I want the html page to be separate from the controller and I am unsure how to get the variables in the html code such as key to work in my html file.

This is my java controller

 
Marshal
Posts: 67226
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered using JSP for your views?

You might benefit from reading this article which outlines how Java web applications should be structured.
 
Henna Ghayas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to integrate this into a bigger project and it does not include using jsp format, so I am trying to stay away from using JSP
 
Bear Bibeault
Marshal
Posts: 67226
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't seem like a very compelling reason. Do all the servlets generate HTML in Java strings? That one of the worst ways to generate the view.

If you want to use a proper controller architecture, your views must be separate from the controllers. Read the article.
 
Henna Ghayas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm it might not be a good way but do you know if it is possible to take my hashmap values and display them on my html file?
 
Bear Bibeault
Marshal
Posts: 67226
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you continue to build the HTML in Java strings (not recommended) then you'd just use normal Java string manipulation code to do it (again, not recommended).
 
Sheriff
Posts: 21603
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this project allow you to use FreeMarker or Thymeleaf to use instead of JSPs? Because outputting HTML like this is never pleasant.
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
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!