{"id":896,"date":"2015-01-30T04:19:09","date_gmt":"2015-01-30T04:19:09","guid":{"rendered":"http:\/\/mooredynasty.net\/?p=896"},"modified":"2015-01-30T04:21:07","modified_gmt":"2015-01-30T04:21:07","slug":"jsp-mvc-application-via-maven","status":"publish","type":"post","link":"https:\/\/mooredynasty.net\/index.php\/2015\/01\/jsp-mvc-application-via-maven\/","title":{"rendered":"JSP MVC Application via Maven"},"content":{"rendered":"<p>After a quick win with the JSP version of Hello World, it seemed that a servlet-based version was only a tweak or two away. Alas, it was not to be.<\/p>\n<p><strong>Coding<\/strong><\/p>\n<p>After using Maven to create another web project, I added <a href=\"http:\/\/www.thejavageek.com\/2013\/08\/11\/mvc-architecture-with-servlets-and-jsp\/\">a simple controller and DTO model object based on this article<\/a>. Not wanting to get involved with Spring, etc., the project required mapping in the web.xml file as well.&#160; <\/p>\n<p>I also updated the web.xml file to version 2.5 of the servlet engine.<\/p>\n<p>A few basic language mistakes later, the code compiled.<\/p>\n<p><strong>Lesson Learned<\/strong>: Unlike .NET\u2019s <em>using<\/em> statement, the Java <em>import <\/em>statement includes classes, not packages.<\/p>\n<p><strong>Packaging<\/strong><\/p>\n<p>Unfortunately, Maven was unable to complete the build because of this error:<\/p>\n<blockquote>\n<p>error: package javax.servlet does not exist<\/p>\n<\/blockquote>\n<p>The solution to this little ditty was <a href=\"http:\/\/stackoverflow.com\/questions\/16262948\/error-package-javax-servlet-does-not-exist\">only a Google away<\/a>.&#160; Missing a dependency in Maven\u2019s POM file:<\/p>\n<blockquote>\n<p>&lt;dependency&gt;     <br \/>&#160; &lt;groupId&gt;javax.servlet&lt;\/groupId&gt;      <br \/>&#160; &lt;artifactId&gt;javax.servlet-api&lt;\/artifactId&gt;      <br \/>&#160; &lt;version&gt;3.0.1&lt;\/version&gt;      <br \/>&#160; &lt;scope&gt;provided&lt;\/scope&gt;      <br \/>&lt;\/dependency&gt;<\/p>\n<\/blockquote>\n<p>Not sure why Maven\u2019s archetype doesn\u2019t include this dependency by default, but adding it to the POM fixed things so Maven was able to package the project into a WAR file.<\/p>\n<p><strong>Deployment<\/strong><\/p>\n<p>Tomcat was able to unpack the WAR file without incident.<\/p>\n<p><strong>Execution<\/strong><\/p>\n<p>Hitting the URL a .NET developer might expect:<\/p>\n<blockquote>\n<p><a title=\"http:\/\/localhost:9999\/dtoexample\/ExampleController\" href=\"http:\/\/localhost:9999\/dtoexample\/examplecontroller\">http:\/\/localhost:9999\/dtoexample\/examplecontroller<\/a><\/p>\n<\/blockquote>\n<p>did not work.&#160; As memory served, though, I was half-expecting it \u2013 Java, like *nix, is a prissy environment when it comes to case, so:<\/p>\n<blockquote>\n<p><a title=\"http:\/\/localhost:9999\/dtoexample\/ExampleController\" href=\"http:\/\/localhost:9999\/dtoexample\/ExampleController\">http:\/\/localhost:9999\/dtoexample\/ExampleController<\/a><\/p>\n<\/blockquote>\n<p>invoked my new controller action.<\/p>\n<p>Unfortunately, the app coughed up a run-time error:<\/p>\n<pre>org.apache.jasper.JasperException: The absolute uri: http:\/\/java.sun.com\/jstl\/core cannot be resolved in either web.xml or the jar files deployed with this application<\/pre>\n<p><strong>The Fix<\/strong><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/4928271\/jstl-1-2-the-absolute-uri-http-java-sun-com-jstl-core-cannot-be-resolved\">More Googling lead to this Stack Overflow article<\/a> \u2013 the original poster was close and the top answer helped a lot.&#160; Basically more missing dependencies in the POM:<\/p>\n<blockquote>\n<p>&lt;dependency&gt;<br \/>\n    <br \/>&#160; &lt;groupId&gt;taglibs&lt;\/groupId&gt;<\/p>\n<p>&#160; &lt;artifactId&gt;standard&lt;\/artifactId&gt;<\/p>\n<p>&#160; &lt;version&gt;1.1.2&lt;\/version&gt;<\/p>\n<p>&lt;\/dependency&gt;<\/p>\n<p>&lt;dependency&gt;<\/p>\n<p>&#160; &lt;groupId&gt;javax.servlet&lt;\/groupId&gt;<\/p>\n<p>&#160; &lt;artifactId&gt;jstl&lt;\/artifactId&gt;<\/p>\n<p>&#160; &lt;version&gt;1.2&lt;\/version&gt;<\/p>\n<p>&lt;\/dependency&gt;<\/p>\n<\/blockquote>\n<p>and a tweak needed to the JSP provided by Maven, which was missing the <em>jsp<\/em> segment for version 1.2 of the <em>jstl<\/em>:<\/p>\n<blockquote>\n<p>&lt;%@ taglib uri=&quot;<a href=\"http:\/\/java.sun.com\/jsp\/jstl\/core&quot;\">http:\/\/java.sun.com\/<strong><u>jsp\/<\/u><\/strong>jstl\/core&quot;<\/a> prefix=&quot;c&quot; %&gt;<\/p>\n<p><\/p>\n<\/blockquote>\n<p>After these adjustments, my little project ran, albeit with another repeat of a self-inflicted wound: Would it kill Sun to provide a real property syntax?&#160; Come on!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After a quick win with the JSP version of Hello World, it seemed that a servlet-based version was only a tweak or two away. Alas, it was not to be. Coding After using Maven to create another web project, I added a simple controller and DTO model object based on &hellip; <\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-896","post","type-post","status-publish","format-standard","hentry","category-development"],"_links":{"self":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts\/896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/comments?post=896"}],"version-history":[{"count":2,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts\/896\/revisions"}],"predecessor-version":[{"id":898,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts\/896\/revisions\/898"}],"wp:attachment":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/media?parent=896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/categories?post=896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/tags?post=896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}