All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nutz.plugins.view.JspView Maven / Gradle / Ivy

There is a newer version: 1.r.69.v20220215
Show newest version
package org.nutz.plugins.view;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nutz.lang.Lang;

public class JspView extends AbstractTemplateViewResolver {
	
	public JspView(String dest) {
		super(dest);
	}
	
	@Override
	public void render(HttpServletRequest req, HttpServletResponse resp,
			String evalPath, Map sharedVars) throws Throwable {
		Iterator> iter = sharedVars.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = iter.next();
			String key = entry.getKey().toString();
			Object val = entry.getValue();
			req.setAttribute(key, val);
		}
		RequestDispatcher rd = req.getRequestDispatcher(evalPath);
        if (rd == null)
            throw Lang.makeThrow("Fail to find Forward '%s'", evalPath);
        // Do rendering
        try {
			rd.forward(req, resp);
		} catch (Exception e) {//Mock 没有javax.servlet.ServletException: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}
	}

	@Override
	protected void init(String appRoot, ServletContext sc) {
		
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy