How to start coding and setting up a web server using java?

So now I think I learned all the basics and terminology for java. but I don’t know how to encode and display a web page with Netbeans in Java.

Most tutorials contain a lot of talk about the various technologies, “Java uses Java Beans, JSPs and servlets,” etc. Where can I find short practical tutorials that actually teach me where to code and then compile and where to put all the files (war, jar, ear ..) in Glassfish to see the output from the web browser. The simplest things that make it possible to understand all these different "layers" that are just classes using classes. It seems like I will never know how I can install a web server with Java, because I can not find this tutorial.

It would be great if someone could post some links to such practical things.

Thanks.

+7
java
source share
8 answers

How to code and display a webpage using NetBeans in Java?

Let it go! Launch NetBeans. I use NetBeans 6.7.1 with Java EE installed, and I have GlassFish installed and bundled, so I don’t have to worry about that. Your setting may vary in detail.

Make File-> New Project and select "Java Web" from the categories. Select "Web Application" and click "Next." Enter the name of the project and adjust the location if you like it. Click Next. The next page should have a server selection dropdown; as outlined above, I have "GlassFIsh v2.1." This is great - as long as NetBeans can interact with any Java application server, this crash course will work fine.

Write down the "context path" - this will be based on the name of the project and basically forms the base of the URL where your application will be located. Click Next. Ignore the next page, for now, that talks about the various frameworks and click Finish.

Grinding, outflow. Ultimately, you should see that your web project is created. This is a very simple application that contains one JSP file and will open in the main editor. It has a bunch of HTML and some JSP syntax.

Take a look at the structure of the project. You have a Web Pages folder that contains the WEB-INF directory and the index.jsp file. This is the same file you are looking at. WEB-INF is the standard directory that contains the metadata used to deploy your application, as well as compiled classes that support it.

The only thing you need to do now to achieve your original goal is to click the Run button or right-click on the project and select Run from the menu. NetBeans will compile and then launch your application server and deploy the application to it. Finally, your web browser should open a new tab with the classic "Hello, world" page.

At the moment, what do you really have? You have an empty web project with one JSP file. You can customize it, but it may not be very interesting. What you are actually looking at is a basic framework in which you can apply your JSP and servlet training as soon as you deal with them.

How to continue the transfer of knowledge? I recommend a decent book or two. The one I used started with “Getting Started with JSP, JSF, and Tomcat Web Development: From Beginner to Professional” (Zambon, Guilio, Apress, ISBN 1-59059-904-7), which has a decent beginner's guide on how JSPs and servlets work together and a handy reference guide for the first.

As soon as possible, you will want to switch from raw servlets and JSPs to combining them in a slightly more flexible way, using one of the frameworks that I skipped earlier. I am not going to tell you what to learn; there are some pretty decent ones. Try Spring MVC or Struts. Once again, I suggest getting a decent book.

+2
source share

I would start by looking at servlets and JSPs. I found this book useful when I read it: Head First Servlets and JSP

+1
source share

Netbeans comes with many sample projects, creates several, and looks at the source code. An already working sample is always a good starting point for your coding.

+1
source share

If you are also interested in using Eclipse, which makes it very easy to build and deploy web applications, here is a good tutorial - WTP Tutorials

+1
source share

You can find the answers in the Java EE 5 Tutorial .

+1
source share

The Java EE stack is pretty sip. I suggest you just look at creating a web application (WAR) and deploy it to Tomcat.

Unfortunately, fully deploying WAR files is quite tedious, so you usually need help from your development environment or web container.

The easiest place to start is probably to install and run Tomcat, and then a fiddle with files on the file system. There is an example application.

0
source share

Hi, to run the code and configure the web server using java, do the following procedure. First you need to install Apache-Tomcat or Jetty in any container of the web container or servlet. And you set the class path of the servlet-api.jar file. Then you will need to save your webpage code in the tomcat web application folder. In the web application folder, you need to create the web-inf folder in which the web.xml file is stored. And after writing the servlet and jsp program, the compiled class files are stored in the class folder of the web-inf folder. JSP files are stored with the WEB-INF folder. You must store all jar files in the LIB folder in the classes folder. The web container will take care of initializing the servlet by loading the class using the inti method. Using a service method, it will create a request and response to two objects.

0
source share

All Articles