i have a problem mapping my url
to reach the servlet class
. i'm calling the servlet by getJSON
function but the simple sysout
doesnt work.
in my jsp i put:
$.getJSON('getMediaListByMediaType/options?dd=' + ddId + '&val=' + $('#mediaType:selected').text(), //some other codes here)
in my web.xml, i have the following:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<javaee:display-name>MediaScratch</javaee:display-name>
<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>
<servlet>
<servlet-name>dropDownServlet</servlet-name>
<servlet-class>jp.co.aeonbank.servlets.LoadDropDownServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dropDownServlet</servlet-name>
<url-pattern>/getMediaListByMediaType/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>5</session-timeout>
</session-config>
as i checked in google developers' tool, it actually can get the correct url but says it is not found
http://IpAddressHere/ProjectNameHere/getMediaListByMediaType/options?dd=mediaNo&val=DVD-R
any idea why? thanks.
Resolved! I figured out that the reason why it cannot reach the servlet
is beacuse the FilterMapping for struts2 catches all the url
that's why servlet-mapping
became useless. In order to prevent the process of entering in default struts2 filter, i have defined this piece of code on my struts.xml
<constant name="struts.action.excludePattern" value="/getMediaListByMediaType/.*"/>
Now it can successfully get the JSON
from my servlet class.