开发者

Struts2 project getting error - package javax.servlet.jsp does not exist

I've been setting up a Struts2 Project in Netbeans7 and actually got the project set up fine using Maven.

This isn't causing much of an issue as the project is working, but Im just getting this error in my jsp file as a red underline.

package javax.servlet.jsp does not exist

I googled a bit and ended up with a solution that had me adding in jsp-api into my dependencies. Once I added this in netbeans stopped showing me the error so i built and ran it again but now I get a server error.

The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:95)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

After looking around here for a bit I came accross this question. I went through the three solutions here:

  1. I am using Tomcat 7
  2. My web.xml servlet version is 2.5 (i think)
  3. I don't really understand this but thought it might be the case as I did put jsp-api.jar in my dependencies and servlet-api.jar is also there.

So I tried removing both jsp-api.jar and servlet-api.jar from my dependencies to see if this would solve the problem. This just took me back to my original problem.

It's not a showstopper as the project is running fine and struts is working. But it is annoying and I would like to get rid of it as I can see it potentially causing problems later on. So if someone could think of something I haven't tried then that would be awesome!

web.xml

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

<web-app metadata-complete="true" 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">
   开发者_运维技巧 <display-name>New tradesman experience</display-name>
    <description>New tradesman experience</description>

    <!-- listeners -->

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
    </listener>

    <!-- context params -->
    <context-param>
        <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
        <param-value>/WEB-INF/tiles-tradesman.xml</param-value>
    </context-param>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:spring-tradesman.xml</param-value>
    </context-param>


    <!-- filters -->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

    <!-- filter mappings -->
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>


try to change the scope of jsp-api and servlet-api in maven, set it provided.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜