• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple web application design with jsp and servlets

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

Thanks!
 
Saloon Keeper
Posts: 15529
364
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recommend reading these articles:
  • The Secret Life of JSPs
  • The Front Man

  •  
    Danger, 10,000 volts, very electic .... tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic