views:

418

answers:

12

I know Java and i've built some stuff with Swing. However, how can I do web development in java? I'm used to PHP/MySQL and I have Apache installed on my dev machine. How can I get it to run java servlets? And also, which database is the best for Java web dev? I'd still prefer to use MySQL.

Please give me some steps I need to take to be able to create a 'hello world' java servlets I can view by typing http://localhost/java.java or something in my browser.

Thanks

+5  A: 

I would use apache Tomcat over apache, you can't really get apache running servlets.

You can however run the mod_jk module to forward particular urls to backend tomcat instances.

EDIT:

http://tomcat.apache.org/tomcat-6.0-doc/index.html has a nice introduction to getting basic examples going

Paul Whelan
And how do i install tomcat?
Click Upvote
You download it from http://tomcat.apache.org/ unzip it and run the bat shell script it comes complete with examples, if you cna get your hands on head first servlets you will find it is a really nice intro to everything you need.
Paul Whelan
+1  A: 

If you're used to Swing then have a look at Wicket. It has a component model that should feel very familiar to a Swing developer. There is a "Hello World" example here

MrWiggles
I wouldn't recommend Wicket to a absolute beginner - first when someone gets the Java EE technologies they can look into Wicket or any other framework for that matter.
Björn
Really? I would've thought it was easier for a beginner as you don't need to know about alot of stuff that's hidden from you
MrWiggles
When a beginner knows how to use beans he might be ready to take on Wicket. ;) My first concern was the use of Maven which the Wicket tutorials use... Not to easy if you don't know what happens behind the curtains!
Björn
I thought the OP was a beginner with Web Dev, not Java fullstop. And I just ignored the Maven stuff and imported the Wicket JARs by hand :)
MrWiggles
With Wicket you have to have high Java knowledge, not JavaEE specifically so it may actually be easier for beginners.And everyone who ignores the Maven project builder gets an automatic plus :)
Esko
+3  A: 

MySQL is not an obstacle if you want to run Java. FYI - Sun (the company behind Java) bought MySQL AB a couple of months back, so the already smooth integration will maybe be even smoother in the future. :)

Developing web applications in Java is not a big step from standard Java development. Take a look at the Java EE page at http://java.sun.com/javaee - that should be your first stop. After that you need an application server (with integrated web server - it easiest) to host your servlets/JSP's/other cool Java web technology - my vote for an application server goes to Glassfish: https://glassfish.dev.java.net/ .

Now you're set to go! Look into some tutorials on Servlets, JSP, JSF, or any other Java EE technology.

Servlet tutorial: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html

JSP: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro.html

JSF: http://www.jsftutorials.net/

Björn
What's the difference between JSP, JSF and servlets?
Click Upvote
+3  A: 

Download a tomcat distribution and start tomcat (catalina-start), or look for a tutorial. From there, browse to "localhost." (http://localhost/)

The Tomcat distribution should come with a "HelloWorld" servlet example. Just click on it on the left of the tomcat start page to run it, and browse the tomcat directory for source code.

Stefan Kendall
+1  A: 

You can start with the J2EE tutorial at http://java.sun.com/j2ee/1.4/docs/tutorial/doc/ and skip straight to Chapter 11 (Java Servlet Technology), and carry on with 12, 13...

You can use Apache Tomcat as a server, which you can get at http://tomcat.apache.org/

talonx
A: 

As a side you could use something other than servlets. For example here is the simplest hello world in Java for the web you are going to see. Plus this framework is far more scalable than any open source Servlet Engine you will find.

ng
+3  A: 
Julien Poulin
+2  A: 

For basic Servlet examples, and in order to run any JEE webapp, download Tomcat , you'll get some example webapps provided with it...

If you're interested in more advanced web applications, you'll soon discover that there are more 'frameworks' and tools out there than one can choose...

Here, I'm just dropping some common names :

  • Struts (old one, MVC model based on a Servlet Controler...)
  • ORM tools : Hibernate, Ibatis... With theses - If you use common SQL - you can switch from any database to another quite quickly !
  • Spring, originally a IoC container, turned into a whole JEE alternative... a whole platform with modules for MVC, DataBase Connection, AOP, User security, anything... ;-)

if you're interested in getting a overview of an application using different frameworks (these and others) you can give a try to Appfuse... It can be an interesting step after the 'hello world', a more complex but also more realistic application to dive into...

VinzzzBarto
+2  A: 

I would recomend you to pick a good IDE as the first step. Although it might seem a bit off-topic, I think this is very important step.

You can pick from various IDEs - best known are Eclipse, NetBeans and IDEA. I have used mostly NetBeans for my development and I think it's the best option for start with web application development - it's free of charge and comes with everything you need already bundled in the installation. On the other hand I don't know the other IDEs very much so maybee someone else would recomend you another option.

With NetBeans, there's an application server bundled with the IDE and you don't have to bother with installation and configuration of the server. You can use supplied wizards and let the IDE create a web application skeleton for you. You also can deploy and try you web application easily with just one click on a button. And that's the best thing for playing around and experimenting :)

You can download it here (pick "java" or "all" bundle). So good luck :)

Martin Lazar
A: 

If its Java, U will surely enjoy reading Kathy Sierra!!

Lakshman Prasad
A: 

Disclamer: I work at IT Mill

Something else you might be interested in is IT Mill Toolkit. Since you are familiar with Swing, as with Wicket, IT Mill Toolkit should be somewhat easy to pick up. I'm not going to go over the pros or cons of either, because I'd probably be voted down for advertising or being biased.

I'm just saying that it's something I think is worth looking at. I personally have a background in PHP, and the first serious things I did with Java was with the toolkit. For what it's worth, I like writing apps with it, and that's why I wanted to mention it.

Henrik Paul
A: 

Have a look at Grails. It's easy to get started with, like Ruby on Rails. It uses Groovy as a scripting language. In the background is a Java App/web server. There is a lot of Java-centric stuff built right in, ie. Spring. Once you get comfortable you can write your own Java classes and drop them in. I think you'll get more bang for your buck starting here, rather then some Hello World project with Tomcat.