user1538526
user1538526

Reputation: 95

Using a servlet with struts 2

I want to know how to use a servlet in conjunction with Struts2 when you have mapped everything to the Struts2 filter. let say I have one servlet in my application also. I was trying in my struts.xml

<constant name="struts.action.excludePattern" value="/YourServlet"/>

Now I want to know what the above line communicates..? what does constant name is doing here..!Please advise

Upvotes: 0

Views: 1234

Answers (2)

Vu Truong
Vu Truong

Reputation: 1883

If you need multi mapping servlet you can using:

<constant name="struts.action.excludePattern" value="/Servletname1, /Servletname2" />

But in struts, you should not using servlet url because it not unity. You can use ajax:

$.ajax({
        url : "nameAction.action?param="+id,
               type : "post",
        data : {
            'id' : id

        },
        success : function(data) {
//          $('#result').html(data);
        },
        error : function(jqXHR, textStatus, errorThrown) {
            $('#result').html("Error");
        }
    });

Upvotes: 1

MohanaRao SV
MohanaRao SV

Reputation: 1125

Source

Why the Filter is mapped with /* and how to configure explicit exclusions (since 2.1.7) In the example above we've mapped the Struts 2 dispatcher to /*, so Struts 2 has a crack at all incoming requests. This is because Struts 2 serves static content from its jar files, including Dojo JavaScript files (if using S2.0, or the Dojo plugin in S2.1+) and FreeMarker templates for the Struts 2 tags that produce HTML.

If we change the filter mapping to something else, for example /*.html, we must take this in to account and extract the content that would normally be served from the Struts 2 jar files, or some other solution.

Since Struts 2.1.7, you are able to provide a comma seperated list of patterns for which when matching against the request URL the Filter will just pass by. This is done via the configuration option struts.action.excludePattern, for example in your struts.xml

<struts>
<constant name="struts.action.excludePattern" value=".*unfiltered.*,.*\\.nofilter"/>
...

Upvotes: 2

Related Questions