Java Enterprise Context
The Java Enterprise Edition (JavaEE) specification, former known as J2EE, defines standards for enterprise application development. Managed by the Java Community Process (JCP), it includes technologies like Servlets, JSP, JDBC, and JPA. The current version is JavaEE 8.
Web Fundamentals
The World Wide Web (WWW) provides access to resources via URLs. Resources are categorized as:
- Static: Unchanging content (HTML, CSS, JS, images)
- Dynamic: Generated content (Servlets, JSP, PHP)
Network types:
- LAN: Local network
- WAN: Internet
System Architectures
- C/S (Client-Server): Dedicated client software, typically in LAN
- B/S (Browser-Server): Web browser-based, accessible over WAN
Tomcat Server
Apache Tomcat is a lightweight, open-source web server implementing Servlet/JSP specifications.
Installation and Setup
Directory structure:
bin/: Startup/shutdown scriptsconf/: Configuration fileswebapps/: Deployed applications
Operations
Startup/Shutdown:
- Windows:
startup.bat/shutdown.bat - Linux:
startup.sh/shutdown.sh
Common Issues:
- Port conflict: Modify
conf/server.xml - Environment: Configure
JAVA_HOME
Application Deployment
Stendard directory layout:
mywebapp/
index.html
WEB-INF/
web.xml
classes/
lib/
Deployment Methods:
- Copy directory to
webapps/ - Package as WAR file:
jar -cvf app.war *
mv app.war $CATALINA_HOME/webapps/
Configuration
Virtual Directory Mapping:
<Context path="/demo" docBase="/var/www/app" />
Default Port Change:
<Connector port="80" protocol="HTTP/1.1" />
HTTP Protocol
HyperText Transfer Protocol governs client-server communication.
Versions
- HTTP/1.0: Single request per connection
- HTTP/1.1: Persistent connections
Request Structure
GET /resource HTTP/1.1
Host: example.com
Accept: text/html
[Body if POST]
Methods:
- GET: Retrieve resource
- POST: Submit data
Response Structure
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1024
<html>...</html>
Common Status Codes:
- 200: Success
- 302: Redirect
- 404: Not Found
- 500: Server Error
Header Format
- Capitalized words separated by hyphens
- Colon-space delimiter
- Comma-separated values
Practical Implementation
Static Content Deployment
- Place HTML/CSS/JS in webapp directory
- Configure default page in
web.xml:
<welcome-file-list>
<welcome-file>home.html</welcome-file>
</welcome-file-list>
Servlet Example
import javax.servlet.*;
import java.io.*;
public class WelcomeServlet extends GenericServlet {
public void service(ServletRequest req, ServletResponse res) {
try {
PrintWriter out = res.getWriter();
out.println("<h1>Welcome</h1>");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Configuration:
<servlet>
<servlet-name>welcome</servlet-name>
<servlet-class>com.example.WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>welcome</servlet-name>
<url-pattern>/greet</url-pattern>
</servlet-mapping>