[英]java try catch block not working using reflection - have no idea why, also maybe a thread error
[英]why IDEA have a error when I use java reflection, but eclipse not
我嘗試使用JAVA反射完成servlet演示。 但提示錯誤。 這些提示僅出現在Eclipse的IDEA中,沒有任何提示。
提示: 在此處輸入圖片描述
像這樣的代碼:
package...
import...
public class ServletDemo02 extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String md=request.getParameter("method");
String path=null;
Class clazz = this.getClass();
try {
Method method=clazz.getMethod(md, HttpServletRequest.class,HttpServletResponse.class);
if(null!=method){
//
path=(String)method.invoke(this, request,response);
}
if(null!=path){
request.getRequestDispatcher(path).forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public String addStu(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("add");
return "/test.html";
}
public String delStu...
public String delStu...
Class
的getMethod
的聲明是
Method getMethod(String name, Class<?>... parameterTypes)
parameterTypes
是一個vararg,至少需要Java5。仔細檢查您的IDE中是否激活了Java 5。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.