I have been doing web development with PHP for the last few years, and like a lot of people, I have a strong dislike for PHP. I also have done lots of Java development, but never web development. Having a good knowledge of Java, I decided I would try web development using JSP. I have read a few article but I am not fully "understanding" it. My first question is, what is the difference between a JSP (Java Servlet Page) and a servlet? Is a JSP not simply a file that contains a servlet and HTML? My second question is can Servlets interact with HTML elements as easily as PHP? Can I check for HTML form input using POST/GET etc.

I was also wondering if Servlets could use "native" java code. By this, I mean can I use the same code that I use in desktop applications/use the same methods and classes that I have already made. What I am trying to get at is, can servlets do (almost) anything that a desktop application can do. Can I access the server's file system to delete/ modify files? Can I use third part java libraries in my JSP?

If someone could clear this up for me that would be great! Thanks in advance!

JSP is very old technology, I'd not advise it for new projects but if you're interested in learning it for the same of things or to work on maintenance of legacy code it's quite viable.

Yes, JSP is essentially a blend of servlets with html. If you look at the compilation stages of a JSP into a runnable artifact this becomes immediately obvious.
A JSP is first transformed into a Java servlet source file, which is then compiled into a Java class that is deployed to the application server.

But directly writing Java code in JSPs is much frowned upon, far better to make taglets and other fragments and include those in the main JSP, keeping it as clear of Java code as possible.

Yes, servlets can make use of any and all Java code, except those parts that create user interface components on screen (obviously). So most AWT and Swing is not going to do anything, though the image manipulation parts work, you just need to stream the resulting images to a ServletOutputStream rather than a Swing component.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.