Skip to content

Instantly share code, notes, and snippets.

@chaitanyamannem
Created October 7, 2013 05:22
Show Gist options
  • Save chaitanyamannem/6862902 to your computer and use it in GitHub Desktop.
Save chaitanyamannem/6862902 to your computer and use it in GitHub Desktop.
JSP: Static inclusion example
/*
* Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/7.0.42
* Generated at: 2013-10-07 05:19:37 UTC
* Note: The last modified time of this file was set to
* the last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class staticInclusionProductSearchMain_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
public String[] getMatchingProducts(String keyword) {
String[] defaultList = { "a", "b", "c" };
if (keyword.equals("tech")) {
String[] techCompanies = { "apple", "google", "oracle" };
return techCompanies;
}
if (keyword.equals("movies")) {
String[] movies = { "AD", "Gladiator", "Tempest" };
return movies;
}
if (keyword.equals("mobiles")) {
String[] mobiles = { "iphone", "sx4", "desire" };
return mobiles;
}
return defaultList;
}
private static final javax.servlet.jsp.JspFactory _jspxFactory =
javax.servlet.jsp.JspFactory.getDefaultFactory();
private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;
static {
_jspx_dependants = new java.util.HashMap<java.lang.String,java.lang.Long>(1);
_jspx_dependants.put("/staticInclusionSearchResultSub.jsp", Long.valueOf(1381122854000L));
}
private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.tomcat.InstanceManager _jsp_instancemanager;
public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
return _jspx_dependants;
}
public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
}
public void _jspDestroy() {
}
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
response.setContentType("text/html");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\n");
out.write("\n");
out.write("<html>\n");
out.write("<body>\n");
out.write("\n");
out.write("\t<p>The search results are:</p>\n");
out.write("\t");
//Get the search keyword from the request
String keyword = request.getParameter("keyword");
out.println("The keyword is " + keyword);
out.write('\n');
out.write(' ');
out.write("<html>\n");
out.write("<body>\n");
out.write("\n");
out.write("\t");
out.println("The keyword is " + keyword);
String[] showResults = getMatchingProducts(keyword);
for (String s : showResults) {
out.write('\n');
out.write(' ');
out.println(s);
}
out.write("\n");
out.write("\n");
out.write("\n");
out.write("\n");
out.write("</body>\n");
out.write("\n");
out.write("\n");
out.write("\n");
out.write("\n");
out.write("</html>");
out.write("\n");
out.write("\n");
out.write("\n");
out.write("\n");
out.write("</body>\n");
out.write("</html>");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
else throw new ServletException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
<%!public String[] getMatchingProducts(String keyword) {
String[] defaultList = { "a", "b", "c" };
if (keyword.equals("tech")) {
String[] techCompanies = { "apple", "google", "oracle" };
return techCompanies;
}
if (keyword.equals("movies")) {
String[] movies = { "AD", "Gladiator", "Tempest" };
return movies;
}
if (keyword.equals("mobiles")) {
String[] mobiles = { "iphone", "sx4", "desire" };
return mobiles;
}
return defaultList;
}%>
<html>
<body>
<p>The search results are:</p>
<%
//Get the search keyword from the request
String keyword = request.getParameter("keyword");
out.println("The keyword is " + keyword);
%>
<%@ include file="staticInclusionSearchResultSub.jsp"%>
</body>
</html>
<html>
<body>
<%
out.println("The keyword is " + keyword);
String[] showResults = getMatchingProducts(keyword);
for (String s : showResults) {
%>
<%
out.println(s);
}
%>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment