Reputation: 394
I have created an enterprise application with an EJB module. But I haven't created a Web war yet.
Then I created a Struts2 web, and add it into the enterprise application.
It's ok. If I use the HTML Tag, but when I use Struts2 tag it throw an exception:
Here:
"HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException:
The Struts dispatcher cannot be found.
This is usually caused by using Struts tags without the associated filter.
Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location] root cause
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter.
Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException:
The Struts dispatcher cannot be found.
This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location] root cause
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter.
Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.
Upvotes: 3
Views: 6363
Reputation: 1
The error clearly says that
This is usually caused by using Struts tags without the associated filter
this means that you have a JSP and struts tags inside it, but this JSP is not used by the filter, because it could be a welcome file, i.e. index.jsp
, error code file, i.e. 404.jsp
, configured in the web.xml
.
These resources are handled by the web server before any filter or servlet mapped to the resource is being involved.
Usually welcome files contain a redirect code to a valid action which then dispatches a JSP that can have Struts tags.
Don't use JSPs directly in your application, use actions instead.
Upvotes: 2
Reputation: 1559
I had the same issue and this is how I solved it :
1 - Make sure your welcome file in the web.xml isn't the one that has the struts tags.
So create a page index.jsp, add it to web.xml as follow :
<welcome-file-list>
<welcome-file>/vues/index.jsp</welcome-file>
</welcome-file-list>
And the index.jsp should only have a code to redirect the user to your actual index page that has the struts tags.
<%
response.sendRedirect(response.encodeRedirectURL(request.getContextPath()) + "/index.action");
%>
index.action is an action without a class, its result is to direct you to you actual index page, so in struts.xml you'll have the following :
<action name="index">
<result>jspPages/index-logged-out.jsp</result>
</action>
Upvotes: 0
Reputation: 1
you need to config the struts default filter dispatcher in the web.xml
Upvotes: -1
Reputation: 11487
The exception clearly says the problem.
For Struts
tags to get resolved, you need to initiliazes the Struts Filter class
via web.xml
.
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Upvotes: 1