Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I separate presentation (HTML) from business logic (Java) when using servlets?

0
Posted

How do I separate presentation (HTML) from business logic (Java) when using servlets?

0

Almost anybody who has ever written a servlet can identify with this one. We all know it’s bad for to embed HTML code in our java source; it’s lame to have to recompile and re-deploy every time you want an HTML element to look a bit different. But what are our choices here? There are two basic options; 1. Use JSP: Java Server Pages allows you to embed Java code or the results of a servlet into your HTML. You could, for instance, define a servlet that gives a stock quote, then use the tag in a JSP page to embed the output. But then, this brings up the same problem; without discipline, your content/presentation and program logic are again meshed. I think the ideal here is to completely separate the two. 2. Use a templating/parsing system: Hmm…I know you’re about to rant about re-inventing the wheel, but it’s not that bad (see below). Plus, it really does pay to take this approach; you can have a group of programmers working on the Java code, and a group of HTML producers main

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123