How do Django concepts map to Java, servlets, Struts 1 and JSP pages?
Asked Answered
A

1

6

I'm taking a class on Java web development but I have far more experience with Django. I understand that some of the concepts are similar but that they're grouped together in different layers and with different names.

How do Django concepts map to Java or vice versa, where do JSP pages, Struts 1.x actions and FormBeans fit into the Django layers?

Ashliashlie answered 23/6, 2013 at 19:34 Comment(4)
It's a bit strange you compare Django with Java, servlets, JSP and Struts. Struts is just one of the many Java Web Application frameworks.Turman
@Turman as I said, I'm taking a class and it's using Struts to introduce us to Java web dev. It's also why I made my answer a community wiki answer, so more info about other frameworks could be added.Ashliashlie
OK, now I see your point. Other than Struts in your question, it's quite interesting to see the parallels/equivalencies between different technologies. +1.Turman
Answering this question properly requires knowing what version of Struts you're targeting. You explicitly mention form beans, which leads me to believe you mean Struts 1--a product that was recently EOL'd, hasn't seen any new development for years, and should never be considered for new projects or for education: its development model is a decade behind the times. Struts 2 is a different framework altogether.Burushaski
P
9

Django concepts

Django's documentation lists these concepts:

  • models
  • view classes
  • templates
  • template tags
  • url conf, routing of URLs
  • forms

Java web development concepts

With Java EE and servlets we have these ideas:

  • servlets
  • Action (struts)
  • JSP page
  • FormBean
  • DynamicFormBean
  • web.xml
  • struts-config.xml

Mapping Java to Django

Important: these concept mappings are only approximations. The Java concepts may allow more, or less, functionality.

JavaBeans are your models, where business logic happens.

The URLConf in Django is approximated by the web.xml and struts-config.xml files. The web.xml file allows you to map urls to servlets and JSP pages among other things. The struts-config.xml file maps URLs to Struts Action classes among other things. Here's how to write Action mappings.

Action classes and servlet classes are views. In Django terms, the struts Action class and servlets are close to a View class handling the most basic dispatch methods. The struts ActionForm classes are closer to a FormView, where request parameters are processed into a form and validated.

ActionForm beans are similar to the Django Form class. You can define these forms in the struts-config.xml file, something you can't do in Django.

JSP pages are similar to templates and have access to template tags. The template language is known as the Expression Language, and the built-in template tags and filters are part of the JSTL (JavaServerPages Standard Tag Library. You can implement custom template tags by following this guide.

When using Struts, the Struts Tag Library can also be considered a set of built-in template tags.

The Struts Tiles component is far more similar to the Django template language, featuring components (a.k.a. "blocks") that can be extended and replaced.

Internationalization is handled by using a properties file. This is similar to using GNU gettext files with Django and creating new translation files for each language you want to support.

You can read this answer for information about session management which is equivalent to Django's Sessions middleware.

Perversion answered 23/6, 2013 at 19:34 Comment(2)
One note: traditionally servlets relate to Controllers in MVC pattern, while JSP relate to View.Turman
true, django has a weird MVT pattern, confusing when you use MVC elsewhere :/Ashliashlie

© 2022 - 2024 — McMap. All rights reserved.