Embedded Tomcat

Reference: http://tomcat.apache.org/maven-plugin-2.2/

http://blog.sortedset.com/embedded-tomcat-jersey/

Required Library

  • tomcat-embed-core.jar
  • tomcat-embed-logging-juli.jar

Example Code

TomcatUtils.java

package com.ittechoffice.server;

import java.io.File;
import java.io.IOException;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;

import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;

public class TomcatUtils {
 public static void main(String[] args) throws LifecycleException, ServletException{
 String webappDirLocation = "src/main/webapp/";
 Tomcat tomcat = new Tomcat();
 tomcat.setPort(8080);
 Context ctx = tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
 Tomcat.addServlet(ctx, "hello", new HelloWorldHttpServlet());
 ctx.addServletMapping("/*", "hello");
 tomcat.start();
 tomcat.getServer().await(); 
 }
}

HelloWorldHttpServlet

package com.ittechoffice.server;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;

public class HelloWorldHttpServlet extends HttpServlet{
 
 public void service(ServletRequest request, ServletResponse response)
 throws ServletException, IOException {
 Writer w = response.getWriter();
 w.write("Hello, World!");
 w.flush();
 }
}

Browser

Image 008

 

 

 

WebSphere – Enable / Disable Security and then Change User Password

Disable Security 

  1. <WAS_INSTALL_DIR>/bin/> wsadmin -conntype NONE
  2. wsadmin> securityoff
  3. wsadmin> exit
  4. Restart the servers.

Change User Password

After disabling the security of WebSphere, the user password can be changed in the Web Console.

Image 004Image 005

 

Enable Security

  1. <WAS_INSTALL_DIR>/bin/> wsadmin -conntype NONE
  2. wsadmin> $AdminTask setGlobalSecurity {-enabled true}
  3. wsadmin> $AdminConfig save
  4. wsadmin> exit
  5. Restart the servers.

 

Reference: 

Difference between Tomcat and JBoss

JBoss is an J2EE application server while Tomcat is only a web server and servlet container. JBoss provided additional functionality when compared to Tomcat such as EJB, deployment, clustering. Therefore, JBoss would be more complex than than Tomcat.

J2EE Application Server

  • Oracle Weblogic
  • IBM Websphere
  • JBoss AS (Renamed to Wildfly in 2014)

Web Server (Servlet Container)

  • Apache Tomcat
  • Eclipse Jetty

In Short, Web Server implements Servlet Spec and Application Server implements J2EE Spec.