views:

1077

answers:

15

I'm looking to start developing for the web using Java - I have some basic Java knowledge, so that's not a problem, but I'm at a loss when it comes to deciphering the various technologies for use in web applications.

What options are available to me? How do they work? Are there any frameworks similar to Django/Ruby on Rails which I could use to simplify things?

Any links which could help with understanding what's available would be much appreciated.

+3  A: 

something like grails ?

there is also the projects from spring

Jean
+7  A: 

I don't know if there's anything quite as nice as Django for Java, but Spring has a light-weight web framework built on J2EE

http://www.springframework.org/about

A flexible MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. Note that a Spring middle tier can easily be combined with a web tier based on any other web MVC framework, like Struts, WebWork, or Tapestry.

Lou Franco
A: 

J2EE is the standard. You can use this to build apps with Java Server Pages, Servlets and EJBs.

Struts is also a very popular framework that uses JSPs and Servlets. Its a bit tricky to get setup but it is a very good option for mid size sites.

http://en.wikipedia.org/wiki/Struts

Brian G
+2  A: 

You'll need to start with servlets and JSP. There are many web frameworks in Java and all of them are based on these two technologies.

Bill the Lizard
+1  A: 

Also Java Server Faces

http://en.wikipedia.org/wiki/Java_Server_Faces

Brian G
+9  A: 

Your basic java web technology is servlets. Servlets let you write Java code that responds to various HTTP events (doGet, doPost, doPut, etc). They're generally used for controllers in the MVC architecture. Link: http://java.sun.com/products/servlet/

JSP lets you write HTML with embedded Java instead of the other way around (in servlets). JSP has been extended via JSF to incorporate more recent architectural advances. This is in the same line as PHP and ASP. This is the view portion of the MVC architecture. Link: http://java.sun.com/developer/technicalArticles/GUI/JavaServerFaces/

A lot of more complex applications utilize Enterprise Java Beans (EJB) for session management, clustering, etc. This isn't a web technology, per se, but you see it go hand-in-hand when dealing with more complex webapps. Alternatives include frameworks such as Spring. EJB: http://docs.jboss.org/ejb3/app-server/tutorial/ Spring: http://www.springframework.org/

Also, you'll want to familiarize yourself with ORM technology (after servlets and JSP/JSF). The leading ORM framework is currently Hibernate. This lets you map SQL tables to java objects and interact with them accordingly. This is more advanced stuff so save it for when you're trying to get your head around EJB/Spring, etc. Link: http://www.hibernate.org/

edit: I forgot to define ORM. It stands for Object Relational Mapping/Mapper (whatever version of "Map" you feel like using :)

MattC
A: 

In general Java is more component-based, i.e. you don't have frameworks that do it all for you (you'll probably have to pick a database access framework yourself, for example). For Data Access I'd recommend Hibernate or iBATIS.

For the front-end there are literally hundreds of frameworks around. Investigate JSF, Wicket, Struts 2, Stripes - whichever one you use depends on your specific needs as they all have different strengths.

And for a business layer I'd recommend the Spring Framework, which is very comprehensive and has a great reference guide / tutorial :)

Phill Sacre
+2  A: 

See also this similar post

toolkit
+1  A: 

This is a very open-ended question. The short answer is "yes" there are frameworks, libraries and standards to do everything from writing things at the HTTP request level up to content management systems in Java.

You can also use other languages (e.g. Python, Ruby, etc) on the JVM for that matter.

For some of the Java-only technologies, investigate JSP/Servlets, Struts, Struts2 (which is the updated version of Webwork), Spring MVC, Tapestry, web4j, Wicket.

There are other frameworks built on the JVM but use languages other than Java such as Grails.

To get started I would download Eclipse (latest version) and Tomcat. Create a new web application in Eclipse. There are guides that can get you started.

Start with learning how JSPs and Servlets work, these are a bit low level and aren't really a framework, but will let you get up and running quickly. From there investigate and choose your framework.

Spring MVC is pretty easy to get set up and going. I'm certain there are others.

Dan Fleet
+2  A: 

You could try Jboss Seam : http://www.seamframework.org/Documentation/GettingStarted

If you are using Eclipe as your IDE there is good integration via Jboss Tools or you can use the Seam-Gen tool that comes with Seam. This allows you to define a database table (or tables) and with a few easy commands, build an entire runnable web project from it. It's a nice way to get the ball rolling.

Damo
+22  A: 

Java frameworks come in two basic flavors. One is called the "Action" Framework, the other the "Component" Framework.

Action frameworks specialize on mapping HTTP requests to Java code (actions), and binding HTTP Requests to Java objects. Servlets is the most basic of the Action Frameworks, and is the basic upon all of the others are built.

Struts is the most popular Action framework, but I can't in good conscience recommend it to anyone. Struts 2 and Stripes are more modern, and very similar to each other. Both are light on the configuration and easy to use out of the box, providing very good binding functionality.

Component Frameworks focus on the UI and tend to promote a more event driven architecture based on high level UI components (buttons, list boxes, etc.). The frameworks tend to hide that actual HTTP request from the coder under several layers. They make developing the more advanced UIs much easier. .NET is a component framework for Windows. On Java, the popular component frameworks are JSF (a standard) and Wicket.

As a rule, if you're creating a "web site". that is something more akin to presenting information (like a blog, or a community site), the Action frameworks work better. These sites tend to be simpler, get bookmarked often, require "pretty URLs" etc. This is generally easier to do with an Action framework.

Component frameworks are much better for things like back office applications with lots of UI elements and complicated workflows. You'll find, particularly with tooling, that these style of apps will go together faster using a component framework. But component frameworks have more complicated request workflow, sometimes relying on hidden state, lots of POST actions, etc. Many have "horrible" URLs, and sometimes create pages that are difficult to bookmark.

Both frameworks can be used for both tasks, just some are more suited to the task than others.

None of these frameworks directly address persistence, but many have extension modules or idioms that work tightly with JPA/EJB3 or Hibernate.

Will Hartung
+6  A: 

Start with JSP backed by logic in Java classes. Or use servlets.

The advantage of using JSP and Servlets is that you gain knowledge of what all the frameworks do under the hood. And that understanding is crucial to figure out how to do X in that particular framework.

Furthermore, JSP is very easy. You can easily see what you're doing and very easily see it when you mess up the view with business logic.

And quite a lot of frameworks (Struts, Spring MVC) use JSP as their view technology. It's a natural first step in web development using Java.

extraneon
+1  A: 

If you already know Ruby On Rails, you can use it with JRuby and deploy to a Java server (like Tomcat) with Warbler.

In pure Java, Wicket has a good approach and is getting quite popular.

Michel
+1  A: 

Before studying those frameworks, why not study first where it all started? Try programming with servlets first, so you could a peek at the core of most of those java web frameworks. It would help you understand J2EE better.

mives
A: 

I learned Java in college back when it was in version 1.1.5. I recently started trying to program for the web, but it didn't make sense until I read Head First Servlets and JSP. There are way more things involved in web development with Java than I ever realized, and without this book, I would have quit and just used PHP.

Joseph