frontcontroller.java

来自「本人大学时大型作业用JAVA做的一个 BBS系统 模式MVC 非struts版 」· Java 代码 · 共 52 行

JAVA
52
字号
package servlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import javax.xml.parsers.*;
import org.xml.sax.*;
import helps.*;
public class FrontController extends HttpServlet
{	
	private ServletConfig config;
	public void init() throws ServletException
	{
		config=this.getServletConfig();
	}
	protected void processRequest(HttpServletRequest req, HttpServletResponse res)
		throws ServletException, IOException
	{	
		try
		{
			ServletContext scx=config.getServletContext();				
			String path = req.getPathInfo().substring(1);
			Action action = ActionHelper.getAction(scx,path);
			String nextView = action.process(scx,path,req,res);		
			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextView);
			dispatcher.forward(req, res);
		}
		catch(ParserConfigurationException pce)
		{
			pce.printStackTrace();
		}
		catch(SAXException saxe)
		{
			saxe.printStackTrace();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}		
	}	
	protected void doGet(HttpServletRequest req, HttpServletResponse res)
		throws ServletException, IOException
	{
		this.processRequest(req, res);
	}	
	protected void doPost(HttpServletRequest req, HttpServletResponse res)
		throws ServletException, IOException
	{		
		this.processRequest(req, res);
	}	

	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?