org.nutz.mvc.NutServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nutz Show documentation
Show all versions of nutz Show documentation
Nutz, which is a collections of lightweight frameworks, each of them can be used independently
package org.nutz.mvc;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.nutz.mvc.config.ServletNutConfig;
/**
* 挂接到 JSP/Servlet 容器的入口
*
* @author zozoh([email protected])
* @author wendal([email protected])
* @author juqkai([email protected])
*/
@SuppressWarnings("serial")
public class NutServlet extends HttpServlet {
private ActionHandler handler;
private String selfName;
private SessionProvider sp;
@Override
public void init(ServletConfig servletConfig) throws ServletException {
Mvcs.setServletContext(servletConfig.getServletContext());
selfName = servletConfig.getServletName();
Mvcs.set(selfName, null, null);
NutConfig config = new ServletNutConfig(servletConfig);
Mvcs.setNutConfig(config);
handler = new ActionHandler(config);
sp = config.getSessionProvider();
}
public void destroy() {
Mvcs.resetALL();
Mvcs.set(selfName, null, null);
if(handler != null)
handler.depose();
Mvcs.setServletContext(null);
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Mvcs.resetALL();
try {
if (sp != null)
req = sp.filter(req, resp, getServletContext());
Mvcs.set(selfName, req, resp);
if (!handler.handle(req, resp))
resp.sendError(404);
} finally {
Mvcs.resetALL();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy