import java.lang.annotation.*;
import java.lang.reflect.*;
import java.io.*;
@Target(value=ElementType.METHOD)
@Retention(value=RetentionPolicy.RUNTIME)
@interface WebServlet{
String urlPatterns();
}
class ServletTest{
@WebServlet(urlPatterns="/now")
void doGet(){
}
}
class A{
public static void main(String args[]) throws Exception{
Method m=ServletTest.class.getDeclaredMethod("doGet");
WebServlet ws=m.getAnnotation(WebServlet.class);
String pattern=ws.urlPatterns();
StringBuffer buffer=new StringBuffer();
buffer.append("<servlet-mapping>");
buffer.append("<url-pattern>"+pattern+"</url-pattern>");
buffer.append("</servlet-mapping>");
String s=buffer.toString();
FileOutputStream out=new FileOutputStream("c:/web.xml");
out.write(s.getBytes());
out.flush();
}
}
'개발하자 > JSP&Servlet' 카테고리의 다른 글
jQuery BlockUI Plugin (0) | 2015.03.28 |
---|---|
annotation (0) | 2015.03.28 |
m.getName().startsWith("set") Bean에 자동셋팅 (0) | 2015.03.28 |
getDeclaredMethod,getAnnotation (0) | 2015.03.28 |
원하는 메서드 이름 얻어오기 getDeclaredMethod (0) | 2015.03.28 |