60 likes | 208 Views
Web development with Java Server Pages (JSP) and Servlets. Julien Thibault / Phil Brewster / Kristina Doing-Harris Julien.thibault@utah.edu. Web development. Web development includes
E N D
Web developmentwith Java Server Pages (JSP) and Servlets Julien Thibault / Phil Brewster / Kristina Doing-Harris Julien.thibault@utah.edu
Web development • Web development includes • web design, web content development, client liaison, client-side/server-side scripting, web server and network security configuration, e-commerce… • Limitations of “static” HTML • HTML only structures data (text, pictures, media) for rendering in the browser • The hosting web server just send the HTML file as is to the user • Does not natively offers ways to interface with data sources (e.g. Databases) • Dynamic web through server-side code • A web server dynamically generates a web page based on the user request • The user’s request is processed on the server-side, and HTML is generated accordingly to represent the response, then finally sent back to the user. • Many technologies and languages available • Microsoft .NET, Java Server Pages • CGI, PHP, ColdFusion
Java Server Pages and Servlets • Java Servlets • Java Classes used to process HTTP requests • Hosted by the web server (typically Apache Tomcat) • Good technology choice if you want to reuse existing Java libraries • Java Server Pages (JSP) • Java technology used to embed server-side code directly into the web page • When the JSP pages are deployed, the server compiles them and creates the corresponding Servlets. • JSP example: • Server-side code is surrounded by the <%and%> tags <html> <head>Hello world test</head> <body> Hello World! <%= new java.util.Date() %> </body> </html>
Using JSP in Eclipse JEE • Open Eclipse JEE and create a new Dynamic Web Project (e.g. helloproject) • The project should include the following folders: • Java Resources/src/: where you put your Java classes (including servlets) • WebContent/: where you put your web pages (html/jsp), and other web content (pictures, CSS) • WebContent/WEB-INF/lib: where you put your Java libraries (jar files) • To create a new JSP page: • Right-click on WebContent/ -> New -> JSP file (e.g. create hello.jsp from previous slide) • To create a new Servlet • Right-click on JavaResources/src/ folder -> New -> Servlet • To deploy your web application • Right-click on the project folder -> Export -> WAR file • Destination: the webapps/ folder of your Apache Tomcat install (e.g. C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\) • The project will be packaged into a WAR file (Web application ARchive) and deployed onto the server • Now you should be able to access you web app at http://localhost:8080/helloproject/hello.jsp
Use CHPC to host your JSP page Connecting to CHPC • Host: sanddunearch.chpc.utah.edu • Login: uNID • Password: uNID password Hosting your JSP pages 1. Create a public_jsp folder in your home directory 2. Copy your web page to that folder (scp command or WinSCP) 3. Now you can access your webpage at: http://webapps.chpc.utah.edu/~[uNID]/[page_name] Ex: http://webapps.chpc.utah.edu/~u0668260/index.jsp Note: if you just copy the WAR file to that folder, it might take a few minutes to actually deploy.