📄 myservletaction.java
字号:
package action;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import tools.ActionTool;
import tools.ReadXmlTool;
import tools.UtilTool;
import config.MyConfig;
import exception.ActionHasError;
import exception.FormHasError;
import exception.ForwardHasError;
public class MyServletAction extends HttpServlet {
private static MyAction action = null;
private static MyMapping mapping = new MyMapping();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 读取XML文件
ReadXmlTool readxml = new ReadXmlTool();
String address = request.getSession().getServletContext().getRealPath(
"/WEB-INF/mystruts-config.xml");
System.out.println(address);
// 得到config对象
File file = new File(address);
MyConfig config = readxml.parse(file);
MyForm form = null;
MyForward forward = null;
// 填充form
try {
form = UtilTool.InsertForm(request, config);
} catch (ActionHasError e1) {
e1.printException();
} catch (FormHasError e1) {
e1.printException();
} catch (ForwardHasError e1) {
e1.printException();
}
System.out.println("-----------"+action);
action = null;
if (action == null) {
try {
action = ActionTool.getMyAction(request,config);
System.out.println(action);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
forward = action.myexecute(mapping, form, request, response);
System.out.println("***********"+forward);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(forward.getForward());
String fwstr = forward.getForward();
String fadd = "";
try {
fadd = ActionTool.getSendAddress(config, fwstr);
System.out.println(fadd);
} catch (ForwardHasError e) {
e.printException();
}
request.getRequestDispatcher(fadd).forward(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -