How do I get started using Java for web development?
OK, here's the easiest question for the day for those of you who have ever done this. I'm learning Java and I heard that Java can be used to build websites. I am coming from a PHP background, so I would really appreciate using a strongly-typed well-de开发者_运维百科signed language like Java for web development. However, either I can't get my search keywords right, or there's not a single guide out there that will explain what I actually need to do to build websites in Java.
For PHP, I would need to install Apache and PHP, or a nice package like WAMP, and start putting php files in the web root.
What is Java's equivalent?
Here is a great article on using the Eclipse IDE and Apache Tomcat for building a simple web application.
Also read up on Java Servlets and Java Server Pages.
Hope thats enough to get you started.
The Java equivalent of PHP is JSP - engines like Tomcat, Jetty, and Resin can interpret Java web applications (which can contain JSP pages), and JSPs send dynamic content to a web client the same way a PHP engine does.
But a JSP just compiles to a Java Servlet, which is a type of object that lets you directly manipulate the Request and Response objects constructed from the app container (Tomcat, Jetty, Resin). If you put HTML directly into a JSP, equivalent Java code is generated that sends the HTML to the Response.
I think you should start by learning about Servlets and webapps - in particular, learn how a web application is organized and how it can be deployed into Tomcat. All of this info can be found in the Tomcat manual: here's a link to the documentation for version 5.5, I think they are up to 6 now but this is the first one google gave me and it's fine for learning on.
http://tomcat.apache.org/tomcat-5.5-doc/index.html
Read the first four sections, as well as the sections on Servlets and JSPs.
Also, here is a pretty good Servlets tutorial: http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
For PHP, I would need to install Apache and PHP, or a nice package like WAMP, and start putting php files in the web root. What is Java's equivalent?
You can create dynamic web pages using Java Server Pages and Tomcat will be used as a servlet container(+web server) in that case.
Java is a large language so there is a lot to learn.
If all you want to do is keep writing in PHP but running on a Java system, then consider using Quercus as that is a PHP5 implementation in Java.
See http://www.caucho.com/resin-3.0/quercus/ for how to get started.
精彩评论