📄 frontcontroller.java
字号:
package ddd.com.servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import ddd.com.action.*;
import ddd.com.form.*;
import ddd.com.config.*;
public class FrontController extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
process(req,res);
}
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
process(req,res);
}
public void process(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
String uri="/error.jsp";
ServletContext sct=getServletContext();
String sTemp=req.getPathInfo();
int index=sTemp.lastIndexOf("/");
String path=sTemp.substring(index+1);
ActionHelper helper=new ActionHelper(sct);
ActionConfig aConfig=helper.getActionConfig(path);
if(aConfig!=null)
{
ActionForm form=helper.getActionForm(aConfig,sct,req,path);
if(aConfig.getValidate() && !form.validate(aConfig,req))
uri=aConfig.getInput();
else
{
Action action=helper.getAction(sct,req,path);
if(action!=null)
{
ForwardConfig forward=action.nextView(aConfig,form,req,res);
uri=forward.getUri();
}
}
}
RequestDispatcher dispatcher=sct.getRequestDispatcher(uri);
dispatcher.forward(req,res);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -