• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
Author and ninkuma
Marshal
Posts: 66784
168
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
Author and ninkuma
Marshal
Posts: 66784
168
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
Author and ninkuma
Marshal
Posts: 66784
168
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: 21423
94
Chrome Eclipse IDE Java 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!