IDEA使用maven中tomcat插件来启动服务器配置

代码

pom



    
        great-parent
        com.fucking.great
        0.0.1-SNAPSHOT
    
    4.0.0
    war
    great-servlert

    
        
            javax.servlet
            javax.servlet-api
            3.0.1
            provided
        
        
            javax.websocket
            javax.websocket-api
            1.1
            provided
        
    
    
        
            
                org.apache.tomcat.maven
                tomcat7-maven-plugin
                2.2
                
                    
                        8000
                    
                    /mvc
                
            
        
    

java

package com.fucking.great.servlert;

import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;

@SuppressWarnings("serial")
@WebServlet("/myServlet12312")
public class MyServlet extends HttpServlet {
	public static final Log log = LogFactory.get();
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/json; charset=utf-8");
		String tt = request.getParameter("tt");
		System.out.println(tt);
		System.out.println(request.getRequestURI());
		System.out.println(request.getPathInfo());

		Method[] gets = ReflectUtil.getMethods(ClassUtil.getClass(request), (filter) -> {
			String name = filter.getName();
			if (name.startsWith("get") && !"getInputStream".equals(name) && filter.getParameterCount() == 0) {
				return true;
			} else {
				return false;
			}
		});
		System.out.println(StrUtil.join(",",gets));
		log.error("类为[{}]的对象[{}]的get方法执行结果length[{}]", ClassUtil.getClassName(request,false), request,gets.length);
		for (Method get : gets) {
			try {
				log.error("方法名为[{}],内容为[{}]",get.getName() , ReflectUtil.invoke(request,get) );
			} catch (Throwable e) {
				e.printStackTrace();
			}
		}

		PrintWriter printWriter = response.getWriter();
		printWriter.write("dsfa访问成功");
		printWriter.flush();
		printWriter.close();
		System.out.println("访问成功");
	}
	
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}
}

参考资料

  • IDEA使用maven中tomcat插件来启动服务器配置

你可能感兴趣的:(Ĵava,#,力盟亚任职)