samedi 8 décembre 2018

why IDEA have a error when I use java reflection, but eclipse not

I tried to use the JAVA reflection complete a servlet Demo. but I got a wrong tips. this tips just only appear in the IDEA, eclipse`s normal, no any tips.

the tips: enter image description here

code like that:

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...





Aucun commentaire:

Enregistrer un commentaire