tags:

views:

26

answers:

2

I have my first JSP page after a couple of years using those framework. It seems that I do not know how to program JSP anymore.

I am using windows, tomcat 6.0.29, the code is attached. I got following error. Then I check the compiled hello_jsp, the line 22 points to following a couple of lines. I do have el-api.jar, jasper-el.jar in the classpath. Even I comment java part in jsp page, it has the same error. Are there something wrong with my web.xml?

hello_jsp:

public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }



java.lang.NullPointerException
      org.apache.jsp.jsp.hello_jsp._jspInit(hello_jsp.java:22)
      org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
      org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:159)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="hello" scope="session" class="com.juhani.uml.test.webapp.jsp.HelloTest" />

Let's say: <%= hello.getGreetings() %>


</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;

<display-name>Simple UML Tool Test</display-name>

    <servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>com.juhani.uml.test.webapp.HelloWorld</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>

    <servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/helloworld</url-pattern>
</servlet-mapping>

    <session-config>
<session-timeout>30</session-timeout>
</session-config>

<!--
    <taglib>
<taglib-uri>/com/sun/web/taglibs/cache</taglib-uri>
<taglib-location>/WEB-INF/sun-web-cache.tld</taglib-location>
</taglib>
-->

</web-app>
A: 

I make it work out. I exclude servlet-api.jar from war file. The reason why I would think about that is that I moved .jsp file to tomcat root directory. Then it works.

A: 

Your problem is that you copied server-specific libraries into your /WEB-INF/lib because it seemingly solved the compilation errors. This is however the wrong solution. You will still run into trouble during runtime because the libraries in /WEB-INF/lib get precedence in classloading and due to the wrong location some mandatory stuff is missing and everything will break.

You should keep those server specific libraries there where they originally belong and not move/copy them around. All you need to do is to just include their disk file system path in the compiletime classpath. The average IDE (Eclipse, Netbeans, etc) can do that in a single click.

BalusC
Thanks. you are absolutely right!!!
You're welcome.
BalusC