We are trying to build up a modular system where jars contain application contexts and jsps along with the classes. Different URIs are located in different jars.
For example lets say we have a request for /monkey/home.html and another for /elephant/home.html. I need monkey to go to WEB-INF/lib/monkey-1.1.jar!/WEB-INF/jsp/monkey/home.jsp and elephant to go to WEB-INF/lib/elephant-1.1.jar!/WEB-INF/jsp/monkey/home.jsp. Then there are other's that are in the main webapps web-inf/jsp such as a request for simply home.html should be found in web-inf/jsp/home.jsp.
Any ideas on how to implement a org.springframework.web.servlet.ViewResolver to be able to find the jsp in the jar? I started something, but its not working:
Code:<bean id="viewResolver" class="com.retrieve.commons.viewResolver.JarViewResolver"> <property name="cache" value="false" /> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> <property name="locations"> <map> <entry key="monkey" value="animals-monkey-5.2.jar"/> <entry key="elephant" value="animals-elephant-5.2.jar"/> </map> </property> </bean>
Errors as:Code:public class JarViewResolver extends org.springframework.web.servlet.view.InternalResourceViewResolver { private String requested; private Map<String, String> locations = new HashMap<String, String>(); public void setLocations(Map<String, String> locations) { this.locations = locations; } protected String getPrefix() { Set<Map.Entry<String, String>> entries = locations.entrySet(); for (Map.Entry entry : entries) { if (requested.contains(entry.getKey().toString())) { return "/WEB-INF/lib/" + entry.getValue().toString() + "!/WEB-INF/jsp/"; } } return super.getPrefix(); } protected AbstractUrlBasedView buildView(String s) throws Exception { requested = s; // /elephant/Home return super.buildView(s); } }
Lets assume the file is indeed in that location, in that jar, and in that web-inf jsp directory. How can I pull a resource from the jar?Code:HTTP Status 404 -The requested resource (/context/WEB-INF/lib/animal-monkey-5.2.jar!/WEB-INF/jsp/monkey/Home.jsp) is not available.
Thanks.


Reply With Quote