首次学习使用velocity,看到地瓜老大的urlmapp servlet 照抄,发现在post的时候可以正常使用布局,而Get时却什么也没有,无反应,一个空白的,这是怎么回事?
index.html 是有一个表单<form>和一个链接<a>
不可能吧,贴点代码来看看是什么问题。
######
<servlet> <servlet-name>velocity</servlet-name> <servlet-class>VelocityServlet</servlet-class> <init-param> <param-name>org.apache.velocity.toolbox</param-name> <param-value>/WEB-INF/cfg/velocity-toolbox.xml</param-value> </init-param> <init-param> <param-name>org.apache.velocity.properties</param-name> <param-value>/WEB-INF/cfg/velocity.properties</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>velocity</servlet-name> <url-pattern>*.vm</url-pattern> </servlet-mapping>
这是web.xml其中URLMappingServlet照抄,没作改变
public class VelocityServlet extends VelocityLayoutServlet{ public final static String CURRENT_URI = "current_uri"; //{index} public final static String REQUEST_URI = "request_uri"; //{/index} protected void processTemplate(HttpServletRequest request, HttpServletResponse response, boolean isPost) { String CUR_URI = (String) request.getAttribute(CURRENT_URI); String REQ_URI =(String) request.getAttribute(REQUEST_URI); log.info("#####>>>> VelocityServlet:"+REQ_URI); log.info(RequestUtils.getParam(request, "p1", "welcome")); log.info(RequestUtils.getParam(request, "page", 1)); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.info("#####>>>> VelocityServlet: doGet"); processTemplate(request,response, false); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.info("#####>>>> VelocityServlet: doPost"); processTemplate(request,response, true); } }
这里只有doPost会用到layout,可以使用layout.vm
velocity.properties input.encoding = UTF-8 output.encoding = UTF-8 tools.view.servlet.error.template = error.vm file.resource.loader.class = org.apache.velocity.tools.view.WebappResourceLoader tools.view.servlet.layout.directory = /WEB-INF/layout/ tools.view.servlet.layout.default.template = layout.vm######
代码看不出来有问题,是不是页面没指定 #set($layout="layout.vm") 啊?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。