我尝试使用JAVA反射完成Servlet演示。 但提示错误。 这些提示仅出现在IDEA中, 日食正常,没有任何提示。
提示: enter image description here
这样的代码:
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...
答案 0 :(得分:0)
getMethod
中Class
的声明是
Method getMethod(String name, Class<?>... parameterTypes)
parameterTypes
是一个变量,至少需要Java5。再次检查是否在您的IDE中激活了Java 5。