Core basic Java web server technologies. Tools Eclipse IDE for Java EE Developers (Netbeans also...

Preview:

Citation preview

Core basic Java web server technologies

Create a dynamic web project

JSPs (Java Servlet Pages)• JSPs are one of the core building blocks of Java web applications,

allowing us to combine HTML and Java seamlessly• JSP lifecycle: http://www.tutorialspoint.com/jsp/jsp_life_cycle.htm • We can embed Java code into JSP with scriptlet tags

<%java.util.Date today = new java.util.Date();String mess = "Today is "+today;

%><%= mess %>Or<%

java.util.Date today = new java.util.Date();String mess = "Today is "+today;out.println(mess);

%>Output

Press CTRL+Space

Scriplets

For deployment

Steps for deployment on your local computer

• Right-click on the project->Export->WAR• Copy the war file into webapps folder from your Tomcat installation folder• Close the Tomcat fromEclipse and open it from Startup • You should be able to seethe results when calling yourweb application from localhost• You can deploy your web application for free on

https://www.openshift.com , Google App Engine, etc by uploading your war

How to import Java classes into JSPs

How to retrieve parameters from the URL in JSPs

Java Servlet• A servlet is a Java class that runs in an "application server" and sends

web pages back to a browser when a user somewhere in the world clicks on a URL.

To get some URL parameters…

Work with scriplets and HTML

The include directive vs the include jsp tag

• Static include includes smth into the page, before compiling and sending it to the browser (directive)• Dynamic include takes place at runtime (jsp tag)

Going from jsp page/servlet to another jsp page/servlet

• In forward, you see the content of your forwarded page, but the url of the initial page.• In redirect, you see for a second the content of your initial page, then you see your redirected page and, also,

its url.

Declaration tag

Summary of JSP tags so far…