Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

Servlet 3.1 is the latest greatest Servlet API version. I needed to figure out the correct Maven dependencies for using a Servlet 3.1 container, Tomcat 8 specifically. This task was made more difficult because the Java Servlet dependencies tend to move over time. It would be so much better if they were consistent and all one had to do was to change the version numbers. Or better yet, why can’t I include the dependency for Expression Language 3.0 and have it pull in all of its transitive dependencies?

The Tomcat documentation had the following:

Tomcat Servlet API JSP API JSTL API Expression Language API
8.0 3.1 2.3 1.2 3.0

It took a bit of tinkering, but I think I have the Maven dependencies for Servlet 3.1 worked out.

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

Most of the Servlet 3.1 dependencies are packaged by Tomcat 8 and should have their scope marked as provided. The JSTL library is not packaged by Tomcat and cannot be scoped as provided. If you do mark it as provided, you will get the following exception when you try to use JSTL

HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

type Exception report

message Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
	org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1302)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
	org.springframework.web.servlet.support.JstlUtils.exposeLocalizationContext(JstlUtils.java:101)
	org.springframework.web.servlet.view.JstlView.exposeHelpers(JstlView.java:135)
	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:142)
	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1243)
	org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.30 logs.

Apache Tomcat/8.0.30

By using the above Maven dependencies, I was able to write a JSP page that used both Expression Language (EL) and JSTL Core Tags. All that is left now is to get to coding the next great webapp that is going to change the world.

April 12th, 2016

Posted In: Glassfish, Java, java ninja, Javaninja, JSP, Servlet Spec, Tomcat

Leave a Comment

I was unable to access the Glassfish admin. This is because remote administration is disabled by default. To enable it, enter the administration console via the asadmin command. I also had to login because my credentials were not properly stored in the password file

asadmin> login
asadmin> domain-start domain1
asadmin> enable-secure-admin

April 14th, 2013

Posted In: Glassfish

Tags: , , , , ,

Leave a Comment

LinkedIn Auto Publish Powered By : XYZScripts.com