JavaWeb Learning Summary: Packaging, Tomcat Architecture, Encryption Principles, and HTTPS Connector Configuration
This guide explains how to package a JavaWeb application into a WAR file, describes Tomcat’s architecture and connectors, introduces symmetric and asymmetric encryption concepts, and shows how to generate a self‑signed certificate and configure an HTTPS connector in Tomcat.
1. Packaging JavaWeb applications: Use the jar command to create a WAR file. Example: packaging the project JavaWebDemoProject into a WAR, then deploy it by copying the WAR into Tomcat’s webapps directory, where Tomcat automatically extracts it on startup.
2. Tomcat architecture: Tomcat starts from server.xml, creating a Server that contains a Service. Each Service defines one or more Connector (e.g., HTTP on port 8080, HTTPS on 8443, AJP on 8009). Connectors forward requests to an Engine, which selects a Host, and each host contains a Context representing a web application.
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="conf/.keystore" keystorePass="123456" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="www.gacl.cn" appBase="F:\JavaWebApps">
<Context path="" docBase="F:\JavaWebApps\JavaWebDemo1" />
</Host>
</Engine>
</Service>
</Server>3. Encryption principles: Symmetric encryption uses a single key for both encryption and decryption (e.g., DES, AES). Asymmetric encryption uses a public‑key/private‑key pair; the public key encrypts data, and only the matching private key can decrypt it. Trust in public keys is established via a Certificate Authority (CA).
4. Generating a self‑signed certificate for Tomcat: Use the JDK keytool utility, e.g., keytool -genkey -alias tomcat -keyalg RSA The command creates a .keystore file containing the certificate. You can list its contents with keytool -list -keystore .keystore.
5. Configuring the HTTPS connector: Copy the generated .keystore to TOMCAT_HOME/conf and add the following Connector element to server.xml:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="conf/.keystore" keystorePass="123456" />After restarting Tomcat, accessing https://localhost:8443/ will present the self‑signed certificate. Browsers will show a security warning because the certificate is not signed by a trusted CA; the warning can be bypassed for testing purposes. The guide also shows how to install the certificate in Internet Explorer and how to remove it.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
