{"id":34519,"date":"2016-03-10T11:00:52","date_gmt":"2016-03-10T09:00:52","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=34519"},"modified":"2019-04-10T13:05:48","modified_gmt":"2019-04-10T10:05:48","slug":"jetty-servlet-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/","title":{"rendered":"Jetty Servlet Example"},"content":{"rendered":"<p>In this example, we will show you how to make use of Jetty &#8211; Java HTTP Web Server and servlet container and run a sample servlet on this server. Jetty is an open source web server developed by Eclipse Foundation. As a part of this example we will create an eclipse project which will have our servlet code and to deploy on jetty, we will configure that project in a war file.<\/p>\n<h2>1. Environment<\/h2>\n<p>In this example, following environment will be used:<\/p>\n<ul>\n<li>Eclipse Kepler 4.3 (as IDE)<\/li>\n<li>Jetty &#8211; version 9.2.15 v20160210<\/li>\n<li>Java &#8211; version 7<\/li>\n<li>Java Servlet Library &#8211; servlet-api-3.0<\/li>\n<\/ul>\n<h2>2. Jetty Servlet Example<\/h2>\n<h3>2.1 Structure of the example<\/h3>\n<p>In this example, we are going to write a simple servlet and run that servlet on Jetty web server. We will package our servlet project in a WAR file. We can then deploy this war file on running jetty server and it will dynamically detect our servlet.<\/p>\n<h3>2.2 Running Jetty<\/h3>\n<p>Make sure you download the correct version of Jetty from <a href=\"http:\/\/download.eclipse.org\/jetty\/\" target=\"_blank\" rel=\"noopener noreferrer\">Download Jetty<\/a>. Certain versions of jetty only run with certain versions of Java. You might run into an error <code> java: unsupported major:minor version 52.0 <\/code>. Once you extract downloaded jetty zip file on your machine, you can open a command prompt and navigate to directory <code>\/demo-base <\/code> and run <code> java -jar ..\/start.jar <\/code>, this will start our jetty web server. To verify everything is alright with our jetty installation, launch a web browser and go to url http:\/\/localhost:8080, it should show a Jetty welcome page.<\/p>\n<h3>2.3 Creating Example Servlet<\/h3>\n<p>We will create a Dynamic Web Project in eclipse. Follow the steps below:<\/p>\n<ol>\n<li>Go to File -&gt; New Project -&gt; Web -&gt; Dynamic Web Project<\/li>\n<li>Provide a name for your project &#8220;FirstServletJetty&#8221; and choose Target runtime as None<\/li>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_34571\" aria-describedby=\"caption-attachment-34571\" style=\"width: 684px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/DynamicWebProject.jpg\" rel=\"attachment wp-att-34571\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/DynamicWebProject.jpg\" alt=\"Create Dynamic Web Project in Eclipse\" width=\"684\" height=\"722\" class=\"size-full wp-image-34571\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/DynamicWebProject.jpg 684w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/DynamicWebProject-284x300.jpg 284w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><\/a><figcaption id=\"caption-attachment-34571\" class=\"wp-caption-text\">Create Dynamic Web Project in Eclipse<\/figcaption><\/figure><\/p>\n<li>Click Next. On Web Module screen, select the checkbox for &#8220;Generate web.xml deployment descriptor&#8221;<\/li>\n<\/ol>\n<p>After creating our project, we will need to sort out dependencies to write our first servlet. Download servlet-api-3.0.jar file and import that in our project&#8217;s build path.<\/p>\n<p><figure id=\"attachment_34579\" aria-describedby=\"caption-attachment-34579\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/BuildDependencies-1.jpg\" rel=\"attachment wp-att-34579\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/BuildDependencies-1.jpg\" alt=\"Add servlet-api jar file to build path\" width=\"800\" height=\"510\" class=\"size-full wp-image-34579\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/BuildDependencies-1.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/BuildDependencies-1-300x191.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/BuildDependencies-1-768x490.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-34579\" class=\"wp-caption-text\">Add servlet-api jar file to build path<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ol>\n<li>Go to Src folder in project directory and right click to select New Servlet<\/li>\n<li>Enter package name: com.javacodegeeksexample<\/li>\n<li>Enter servlet name: FirstServlet<\/li>\n<li>Keep default options and click Finish<\/li>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_34572\" aria-describedby=\"caption-attachment-34572\" style=\"width: 832px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/CreateFirstServlet.jpg\" rel=\"attachment wp-att-34572\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/CreateFirstServlet.jpg\" alt=\"Create First Servlet \" width=\"832\" height=\"573\" class=\"size-full wp-image-34572\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/CreateFirstServlet.jpg 832w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/CreateFirstServlet-300x207.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/CreateFirstServlet-768x529.jpg 768w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><\/a><figcaption id=\"caption-attachment-34572\" class=\"wp-caption-text\">Create First Servlet<\/figcaption><\/figure><\/ol>\n<h3>2.4 Modifying Example Servlet<\/h3>\n<p>Now we can write our code in the servlet we just created. We can write our code in <code> doGet <\/code> or <code> doPost <\/code>. We will write very simple print statement to see how our servlet behave once deployed on webserver.<\/p>\n<p>This is how the final code of FirstServlet looks:<\/p>\n<p><span style=\"text-decoration:underline\"><em>FirstServlet.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeksexample;\n\nimport java.io.IOException;\nimport javax.servlet.ServletException;\nimport javax.servlet.annotation.WebServlet;\nimport javax.servlet.http.HttpServlet;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\n\/**\n * Servlet implementation class FirstServlet\n *\/\n@WebServlet(\"\/FirstServlet\")\npublic class FirstServlet extends HttpServlet {\n\tprivate static final long serialVersionUID = 1L;\n\n    \/**\n     * Default constructor. \n     *\/\n    public FirstServlet() {\n        \/\/ TODO Auto-generated constructor stub\n    }\n\n\t\/**\n\t * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)\n\t *\/\n\tprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n\t\t\n\t\tresponse.setContentType(\"text\/html\");\n\t\tresponse.getWriter().println(\"First Servlet on Jetty - Java Code Geeks\");\n\t}\n\n\t\/**\n\t * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)\n\t *\/\n\tprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n\t\t\n\t}\n\n}\n<\/pre>\n<p>Save your source code file and build the project in eclipse.<\/p>\n<h3>2.5 Deploying your servlet on Jetty<\/h3>\n<ol>\n<li>Save project -&gt; Export -&gt; Web -&gt; WAR file<\/li>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_34573\" aria-describedby=\"caption-attachment-34573\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ExportAsWAR.jpg\" rel=\"attachment wp-att-34573\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ExportAsWAR.jpg\" alt=\"Export the project as WAR file\" width=\"800\" height=\"573\" class=\"size-full wp-image-34573\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ExportAsWAR.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ExportAsWAR-300x215.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ExportAsWAR-768x550.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-34573\" class=\"wp-caption-text\">Export the project as WAR file<\/figcaption><\/figure><\/p>\n<li>Save this WAR file in \/demo-base\/webapps directory<\/li>\n<li>If jetty is already running, it should detect your new servlet deployed OR you can restart the jetty server<\/li>\n<\/ol>\n<h3>2.6 Running the Servlet<\/h3>\n<p>To verify everything is correct, you can access this servlet in webbrowser at http:\/\/localhost:8080\/FirstServletJetty\/FirstServlet<\/p>\n<p><figure id=\"attachment_34570\" aria-describedby=\"caption-attachment-34570\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/JettyServletExample-1.jpg\" rel=\"attachment wp-att-34570\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/JettyServletExample-1.jpg\" alt=\"Running the servlet in browser\" width=\"810\" height=\"514\" class=\"size-full wp-image-34570\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/JettyServletExample-1.jpg 810w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/JettyServletExample-1-300x190.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/JettyServletExample-1-768x487.jpg 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><figcaption id=\"caption-attachment-34570\" class=\"wp-caption-text\">Running the servlet in browser<\/figcaption><\/figure>[ulp id=&#8217;xFHGZUmgemwCMrAR&#8217;]<\/p>\n<p>Text on this webpage is coming from whatever we printed in <code> doGet <\/code> method.<\/p>\n<h3>2.7 More with Servlet<\/h3>\n<p>This was a very simple servlet to run on jetty. We can do more complicated <code> jsp <\/code> or <code> html <\/code> pages to call servlets to handle requests.<\/p>\n<p>Let&#8217;s add a simple form on an html page and do get action and post action subsequently.<\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;meta charset=\"ISO-8859-1\"&gt;\n&lt;title&gt; First HTML PAGE &lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;p&gt;Let's Test doPost.&lt;\/p&gt;\n&lt;form method=\"POST\" action=\"FirstServlet\"\/&gt;\n&lt;input name=\"field\" type=\"text\" \/&gt;\n&lt;input type=\"submit\" value=\"Submit\" \/&gt;\n&lt;\/form&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n\n<\/pre>\n<p>Now if you see this html page has a <code> form <\/code> with method <code> POST <\/code> which will get called through action <code> FirstServlet <\/code>. Once the form is submitted, <code> FirstServlet <\/code> will call <code> doPost <\/code> to handle the request posted through form submission.<\/p>\n<p>We can modify <code> doPost <\/code> method to read parameters posted through form.<\/p>\n<pre class=\"brush:java\">\/**\n* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)\n*\/\nprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n\tresponse.getWriter().println(\"In POST - First Servlet content - Java code geeks\");\n\tresponse.getWriter().println(request.getParameter(\"field\"));\n\t\t\n}\n<\/pre>\n<p>Most companies build their login pages through form like this and then in doPost handles the submission of those forms for authentication. Once we build our project and export it as a war file to deploy on server, we can access our html page like this http:\/\/localhost:8080\/FirstServletJetty\/FirstPage.html. Output will look like below<\/p>\n<p><figure id=\"attachment_34710\" aria-describedby=\"caption-attachment-34710\" style=\"width: 796px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/FirstPageHTML.jpg\" rel=\"attachment wp-att-34710\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/FirstPageHTML.jpg\" alt=\"First Page Sample Form Submission - doPost\" width=\"796\" height=\"529\" class=\"size-full wp-image-34710\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/FirstPageHTML.jpg 796w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/FirstPageHTML-300x199.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/FirstPageHTML-768x510.jpg 768w\" sizes=\"(max-width: 796px) 100vw, 796px\" \/><\/a><figcaption id=\"caption-attachment-34710\" class=\"wp-caption-text\">First Page Sample Form Submission &#8211; doPost<\/figcaption><\/figure><\/p>\n<p>You can type something in the textbox and press <code> Submit <\/code>. Result will be as shown below<\/p>\n<p><figure id=\"attachment_34711\" aria-describedby=\"caption-attachment-34711\" style=\"width: 812px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/doPostMethodResult.jpg\" rel=\"attachment wp-att-34711\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/doPostMethodResult.jpg\" alt=\"doPost result \" width=\"812\" height=\"473\" class=\"size-full wp-image-34711\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/doPostMethodResult.jpg 812w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/doPostMethodResult-300x175.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/doPostMethodResult-768x447.jpg 768w\" sizes=\"(max-width: 812px) 100vw, 812px\" \/><\/a><figcaption id=\"caption-attachment-34711\" class=\"wp-caption-text\">doPost result<\/figcaption><\/figure><\/p>\n<h2>3. Conclusion<\/h2>\n<p>In this example, we saw how to deploy a simple servlet on a jetty web server. Another way of mapping your servlet is by adding a servlet-mapping in web.xml of your Dyanmic Web Project, but in that case you will need to remove the annotations <code> @WebServlet <\/code> in your java source code.<\/p>\n<p><figure id=\"attachment_34575\" aria-describedby=\"caption-attachment-34575\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ServletMapping-1.jpg\" rel=\"attachment wp-att-34575\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ServletMapping-1.jpg\" alt=\"Mapping the servlet\" width=\"800\" height=\"514\" class=\"size-full wp-image-34575\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ServletMapping-1.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ServletMapping-1-300x193.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/ServletMapping-1-768x493.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-34575\" class=\"wp-caption-text\">Mapping the servlet<\/figcaption><\/figure><\/p>\n<h2>4. Download the eclipse project<\/h2>\n<p>This was an example of Servlet on Jetty.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/JettyServletExample.zip\">JettyServletExample<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example, we will show you how to make use of Jetty &#8211; Java HTTP Web Server and servlet container and run a sample servlet on this server. Jetty is an open source web server developed by Eclipse Foundation. As a part of this example we will create an eclipse project which will have &hellip;<\/p>\n","protected":false},"author":91,"featured_media":1239,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[1052],"class_list":["post-34519","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jetty","tag-servlet"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Jetty Servlet Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example, we will show you how to make use of Jetty - Java HTTP Web Server and servlet container and run a sample servlet on this server. Jetty is\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Jetty Servlet Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example, we will show you how to make use of Jetty - Java HTTP Web Server and servlet container and run a sample servlet on this server. Jetty is\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-03-10T09:00:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-10T10:05:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yogesh Mali\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@yogeshmali\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yogesh Mali\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/\"},\"author\":{\"name\":\"Yogesh Mali\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/2baca97f7fa994c7c6a0449b07f9ef7b\"},\"headline\":\"Jetty Servlet Example\",\"datePublished\":\"2016-03-10T09:00:52+00:00\",\"dateModified\":\"2019-04-10T10:05:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/\"},\"wordCount\":829,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\",\"keywords\":[\"servlet\"],\"articleSection\":[\"jetty\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/\",\"name\":\"Jetty Servlet Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\",\"datePublished\":\"2016-03-10T09:00:52+00:00\",\"dateModified\":\"2019-04-10T10:05:48+00:00\",\"description\":\"In this example, we will show you how to make use of Jetty - Java HTTP Web Server and servlet container and run a sample servlet on this server. Jetty is\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"jetty\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jetty\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Jetty Servlet Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/2baca97f7fa994c7c6a0449b07f9ef7b\",\"name\":\"Yogesh Mali\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/Yogesh-Mali_avatar_1457206862-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/Yogesh-Mali_avatar_1457206862-96x96.jpg\",\"caption\":\"Yogesh Mali\"},\"description\":\"Yogesh currently lives in Minneapolis and works as a Senior Software Engineer. He has a masters degree in Computer Science from University of Minnesota, Twin Cities. At graduate school, he did research in programming languages because of his love for functional and object oriented programming. Currently he delves into more details of Java, web development and security. Previously he worked as a product manager to create web application for health insurance brokers. In his free time, he listens to music and writes fictional stories.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"https:\/\/www.instagram.com\/yogsma\/\",\"https:\/\/www.linkedin.com\/in\/yogeshmali\",\"https:\/\/x.com\/yogeshmali\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yogesh-mali\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Jetty Servlet Example - Java Code Geeks","description":"In this example, we will show you how to make use of Jetty - Java HTTP Web Server and servlet container and run a sample servlet on this server. Jetty is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/","og_locale":"en_US","og_type":"article","og_title":"Jetty Servlet Example - Java Code Geeks","og_description":"In this example, we will show you how to make use of Jetty - Java HTTP Web Server and servlet container and run a sample servlet on this server. Jetty is","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2016-03-10T09:00:52+00:00","article_modified_time":"2019-04-10T10:05:48+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","type":"image\/jpeg"}],"author":"Yogesh Mali","twitter_card":"summary_large_image","twitter_creator":"@yogeshmali","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yogesh Mali","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/"},"author":{"name":"Yogesh Mali","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/2baca97f7fa994c7c6a0449b07f9ef7b"},"headline":"Jetty Servlet Example","datePublished":"2016-03-10T09:00:52+00:00","dateModified":"2019-04-10T10:05:48+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/"},"wordCount":829,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","keywords":["servlet"],"articleSection":["jetty"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/","name":"Jetty Servlet Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","datePublished":"2016-03-10T09:00:52+00:00","dateModified":"2019-04-10T10:05:48+00:00","description":"In this example, we will show you how to make use of Jetty - Java HTTP Web Server and servlet container and run a sample servlet on this server. Jetty is","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-servlet-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"jetty","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jetty\/"},{"@type":"ListItem","position":5,"name":"Jetty Servlet Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/2baca97f7fa994c7c6a0449b07f9ef7b","name":"Yogesh Mali","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/Yogesh-Mali_avatar_1457206862-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/Yogesh-Mali_avatar_1457206862-96x96.jpg","caption":"Yogesh Mali"},"description":"Yogesh currently lives in Minneapolis and works as a Senior Software Engineer. He has a masters degree in Computer Science from University of Minnesota, Twin Cities. At graduate school, he did research in programming languages because of his love for functional and object oriented programming. Currently he delves into more details of Java, web development and security. Previously he worked as a product manager to create web application for health insurance brokers. In his free time, he listens to music and writes fictional stories.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/www.instagram.com\/yogsma\/","https:\/\/www.linkedin.com\/in\/yogeshmali","https:\/\/x.com\/yogeshmali"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yogesh-mali\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/34519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/91"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=34519"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/34519\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1239"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=34519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=34519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=34519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}