= JSP = Java Server Pages == Maven example == {{{#!highlight sh cd /tmp mkdir jspExample cd jspExample }}} === pom.xml === {{{#!highlight xml 4.0.0 test dummy 1.0 war javax javaee-web-api 6.0 provided }}} {{{#!highlight sh mkdir -p src/main/webapp/WEB-INF }}} === nano src/main/webapp/WEB-INF/web.xml === {{{#!highlight xml }}} === src/main/webapp/index.jsp === {{{#!highlight html <%@page import="org.allowed.bitarus.Handler" %> <% //Handler h = new Handler(request,response,out); %> <% Handler h = new Handler(pageContext); %>

Hello

World

<% h.writeHandler(); %>

<% out.print("Your IP address is " + request.getRemoteAddr()); %>

<% h.writeIP(); %>

}}} {{{#!highlight sh * mkdir -p src/main/java/org/allowed/bitarus }}} === nano src/main/java/org/allowed/bitarus/TestBean.java === {{{#!highlight java /* mkdir -p src/main/java/org/allowed/bitarus kate src/main/java/org/allowed/bitarus/TestBean.java */ package org.allowed.bitarus; import java.util.logging.Logger; import java.util.logging.Level; public class TestBean{ private String name; private Logger logger; public TestBean(){ this.logger = Logger.getLogger(this.getClass().getName() ); this.logger.log(Level.INFO,"Created test bean"); this.name="Ioooo"; } public String getName(){ this.logger.info("getName called"); return this.name; } public void setName(String name){ this.name=name; } } }}} === nano src/main/java/org/allowed/bitarus/Handler.java === {{{#!highlight java package org.allowed.bitarus; import java.util.logging.Logger; import java.util.logging.Level; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; /* mkdir -p src/main/java/org/allowed/bitarus http://localhost:8081/dummy-1.0/index.jsp?user=TestASD */ public class Handler{ private ServletRequest request; private ServletResponse response; private JspWriter out; public Handler(ServletRequest request, ServletResponse response,JspWriter out){ this.request = request; this.response = response; this.out = out; } public Handler(PageContext pageContext){ this.request = pageContext.getRequest(); this.response = pageContext.getResponse(); this.out = (JspWriter) pageContext.getAttribute(pageContext.OUT) ; } public void writeHandler(){ try{ this.out.println(String.format("

Handler up %s

" , this.request.getParameter("user") )); } catch(Exception ex){ } } public void writeIP(){ try{ this.out.print("!!! Your IP address is " + this.request.getRemoteAddr()); } catch(Exception ex){ } } } }}} Structure: {{{ . ├── pom.xml └── src └── main ├── java │   └── org │   └── allowed │   └── bitarus │   ├── Handler.java │   └── TestBean.java └── webapp ├── index.jsp └── WEB-INF └── web.xml 8 directories, 5 files }}} {{{#!highlight sh ab -n 100 -c 100 http://localhost:8081/dummy-1.0/index.jsp?user=TestASD }}} Deploy in || '''Tomcat Version''' || '''JVM Version''' || '''JVM Vendor''' || '''OS Name''' || '''OS Version''' || '''OS Architecture''' || '''Hostname''' || '''IP Address''' || || Apache Tomcat/7.0.53 || 1.7.0_15-b03 || Oracle Corporation || Linux || 3.2.45-smp || i386 || darkstar || 127.0.0.1|| {{{#!highlight sh git clone https://github.com/vborrego/jsp-example.git }}}