Java servlets vs Java class in webapp

I am new to Java / Servlets / Tomcat etc., but have a good understanding of web applications since my days as a CGI / PHP developer.

I have a JSP index.jsp that represents a table from a database.

I have Results.class , which is a normal Java class (and not a servlet) that queries the database and returns a string from a method: public static String displayAllResults()

The returned row is an html table.
So in my index.jsp there is a line that says something like:

String table = Result.displayAllResults();

And then the table is displayed as I hoped - all is well!

My question is this: is there any advantage / disadvantage of using regular Java classes instead of Java servlets in this way, or should I port all my classes to servlets to add functionality?

+4
source share
4 answers

You really should use MVC frameworks like Spring MVC or struts2. You should always have clear abstractions:

  • Dao level
  • Service level
  • Business level
  • Model Objects
  • DTO's
  • Helpers / Utils

EL-, JSTL/OGNL JSP. . - MVC, , , !

- DisplayTag Jqgrid ( Ajax)

+1

, - Java JSP. JSP HTML, , Locale . PHP, . .

+1

, Servlet, JSP normal classes .

, JSP View, UI jsp.

Servlets , , .

Normal java classes , -.

0

, . - , , , . -, - . , .

If you look at the fact that Spring has only one servlet (dispatcher) that calls controllers, so developers will never have to create their own servlets, and their controllers can be tested more easily.

0
source

All Articles