I am using the <stripes:link> tag to link to JSP pages located in WEB-INF directory. I understand that this is a common good practice to do.
I have managed to point to JSP pages through ActionBeans but I find this an overkill. I also have managed to point to JSP files outside WEB-INF. After som research I have found some generic advice to look at NameBasedActionResolver.
<stripes:link href="showAllBooks.jsp">
Show all books
</stripes:link>
This code finds the showAllBooks.jsp outside the WEB-INF directory.
I have also find some code for a custom ActionResolver (if this is the only way to do in.):
package com.zetcode.resolver;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.controller.NameBasedActionResolver;
public class MyActionResolver extends NameBasedActionResolver {
@Override
public Class<? extends ActionBean> getActionBeanType(String path) {
Class<? extends ActionBean> cls = super.getActionBeanType(path);
if (cls == null) {
ActionBean bean = handleActionBeanNotFound(null, path);
if (bean != null) {
return bean.getClass();
}
}
return null;
}
@Override
protected List<String> getFindViewAttempts(String url) {
List<String> defaultViews = super.getFindViewAttempts(url);
List<String> customViews = new ArrayList<>(defaultViews.size());
defaultViews.stream().forEach((view) -> {
customViews.add("/WEB-INF/jsp" + view);
});
return customViews;
}
}
Is using a custom action resolver the only way to do it and if so, how to make it work? I think that it should be specified as a filter in web.xml but I have no clue how and if it won't interfere with the existing filters.
Aucun commentaire:
Enregistrer un commentaire