Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to start coding and setting up a web server with java?

Tags:

java

so now i think i have learned all basics and terminology for java. but what i don´t know is how to code and display a web page with Netbeans in Java.

the most tutorials contains lots of talks about different technologies "Java uses Java Beans, JSP and servlets" and so on. Where can i find short practical tutorials that actually teach me where to code what and then compile and where to put all the files (war, jar, ear..) in Glassfish to be able to see the output from a Web browser. Simples things that makes one understand all these different "layers" which are just classes using classes. Feels like i never get to know how i can put up a web server with Java cause I can´t find this kind of tutorials.

Would be great if someone could send some links to such practical stuff.

Thanks.

like image 503
ajsie Avatar asked Jan 10 '10 15:01

ajsie


People also ask

Can you code a website with Java?

Java Web Application is used to create dynamic websites. Java provides support for web application through Servlets and JSPs. We can create a website with static HTML pages but when we want information to be dynamic, we need web application.

Does Java have a web server?

Java 18's Simple Web Server is a minimal HTTP static file server that was added in JEP 408 to the jdk. httpserver module.

Which web server is used for Java?

Apache Tomcat One of the more popular web servers in the Java ecosystem is Apache Tomcat. You can check the latest version of Apache Tomcat and the support Java version(s) on the project's website.


2 Answers

This is the first such document I found: http://www.java-tips.org/java-tutorials/tutorials/introduction-to-java-servlets-with-netbeans.html

More:

  • http://netbeans.org/kb/docs/web/quickstart-webapps.html
  • http://blogs.oracle.com/jonasdias/entry/webservices_with_jsp_on_netbeans
  • http://www.fuzzylizard.com/archives/2005/09/18/628/
  • http://cit.wta.swin.edu.au/cit/subjects/CITP0014/tutorials/netbeans/tomcat/Running_Tomcat_from_Netbeans.html
  • http://supportweb.cs.bham.ac.uk/documentation/java/servlets/netbeans-webapps/

I even found a small ebook on this (PDF!) http://www.comp.dit.ie/bduggan/Courses/projects/Getting%20Started%20with%20Tomcat%20&%20NetBeans.pdf

like image 117
Carl Smotricz Avatar answered Sep 25 '22 07:09

Carl Smotricz


How do I code and display a web page with NetBeans in Java?

Let's go! Fire up NetBeans. I'm using NetBeans 6.7.1 with the Java EE stuff installed, and I've got a GlassFish installed and tied up, so I don't have to care about that stuff. Your setup might differ in the details.

Do a File->New Project, and pick "Java Web" from the categories. Select "Web Application" and hit Next. Enter a project name and tweak the location, if liked. Hit Next. The next page should have a server selection drop-down; as hinted above, mine has "GlassFIsh v2.1" selected. That's fine - as long as NetBeans can interact with a Java application server of some sort, this crash course will run okay.

Make a note of the "context path" - this will be based on the project name, and basically forms the base of the URL at which your application will reside. Hit Next. Ignore the next page, for now, which talks about various frameworks, and hit Finish.

Churn, churn. You should eventually see your web project created. It's a very simple application which contains a single JSP file, and that will be open in the main editor. It's got a bunch of HTML in it, and some JSP syntax.

Take a look at the project structure. You've got a "web pages" folder which contains a WEB-INF directory, and an index.jsp file. That's the same file you're looking at. WEB-INF is a standard directory which contains the metadata used to deploy your application, and also the compiled classes that power it.

The only thing you should need to do now, in order to get to the original objective, is to hit the big ol' Run button, or right-click on the project and select "Run" from the menu. NetBeans will compile, and then fire up your application server and deploy the application to it. Finally, your web browser should pop open a new tab with the classic "Hello, world" page in it.

At this point, what do you actually have? You've got an empty web project with a single JSP file in it. You could customise it, but that's maybe not very exciting. What you're really looking at is a basic framework in which you can apply your learning of JSP and of servlets as you get to grips with them.

How to proceed with said knowledge transfer? I recommend a decent book or two. The one I used to get going was "Beginning JSP, JSF and Tomcat Web Development: From Novice to Professional" (Zambon, Guilio; Apress; ISBN 1-59059-904-7), which has a decent beginner's guide to how JSP and servlets work together, and a handy reference guide for the former.

As soon as possible, you're going to want to migrate away from raw servlets and JSP to tying them together in a slightly more flexible way using one of the frameworks I skipped over earlier. I'm not going to tell you which one to learn; there are several pretty decent ones. Try Spring MVC, or Struts. Once again, I'd suggest getting a decent book.

like image 42
Rob Avatar answered Sep 24 '22 07:09

Rob