簡體   English   中英

為什么當我使用Java反射時IDEA會出錯,但是Eclipse沒有

[英]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...

ClassgetMethod的聲明是

Method getMethod(String name, Class<?>... parameterTypes)

parameterTypes是一個vararg,至少需要Java5。仔細檢查您的IDE中是否激活了Java 5。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM