Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple web application design with jsp and servlets  RSS feed

Bordi Eszter
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to design properly a simple 1to50 game (yes, the one that is so popular among mobile apps), but as a web application that allows two player games. I tried to document myself on the technologies I could use and came to the decision that some kind of Java would be suitable. I know that HTML, HTML5, CSS, JavaScript are client side languages with what I can basically design the client application that runs on a web browser. I installed Tomcat web server, configured Java Servlet API, done some research on Servlets and JSP, but I still cannot really imagine how all of this can work. So I would appreciate some enlightening. Servlets form the Controller, JSP files the Model? How can I make them communicate, how can Servlets "tell" JSP files what to dynamically generate? Can JSP files communicate with JavaScript? Is JavaScript even necessary? Is this a good approach?
Here are some links I found kind of useful:
Tips related to design
Servlet tutorial
JSP book

Note: I thought that this question is not basically about a specific thing regarding JSP or Servlets, more about design and general concept, that is why I put this question under beginning Java.

Stephan van Hulst
Saloon Keeper
Posts: 7693
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Bordi, welcome to CodeRanch!

A lot of these things are all capable of doing the same things, in different ways. They have their advantages and disadvantages in certain situations.

Servlets, JSPs, and JavaScript can all be used to serve the user with dynamic web content. JavaScript does this on the client's end by running in the browser and modifying HTML, while Servlets and JSPs generate content on the server's side (usually in the form of HTML) and only afterwards send it to the client.

JSPs are very similar to HTML pages, except that you can embed little bits of Java that are run before the page is served. This is very useful to generate dynamic content if you're using a lot of HTML; JSPs can act as a template for your site.

Servlets however are much more Java oriented, in which you use a lot of Java and little HTML to generate the page. They are especially useful if you're generating content that is not HTML, like JSON or XML.

The advantage of JavaScript is that it's distributed. The work is done by the clients, so this relieves pressure from the server. The disadvantage is that the server has no control over what eventually happens, it's all in the hands of the client's browser. Important security checks and validation should always be done on the server side.

JSPs are useful when you have a pretty big static layout for your page, but you just need to pop in bits and pieces of dynamic content.

Servlets are good if you need to generate a lot of dynamic material on the server. The problem is that the code can become cluttered very fast if you need to output a lot of HTML.

Usually, you use a combination of techniques to benefit from all the advantages at the appropriate times.
Bear Bibeault
Author and ninkuma
Posts: 66141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend reading these articles:
  • The Secret Life of JSPs
  • The Front Man

    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!