Last active
March 7, 2020 08:41
-
-
Save jacknie84/104c5c47513e2e09df5c940f6c6dc8bc to your computer and use it in GitHub Desktop.
JSP에서 객체 한개 브라우저 로깅
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
String name = "[[INSERT ATTRIBUTE NAME]]"; | |
Object object = pageContext.findAttribute(name); | |
if (object != null) { | |
java.io.Writer writer = pageContext.getOut(); | |
Class<?> beanClass = object.getClass(); | |
String groupName = beanClass.getName() + " instance description"; | |
writer.write("<script>console.group('" + groupName + "');"); | |
java.lang.reflect.Method[] methods = beanClass.getMethods(); | |
for (int i = 0; i < methods.length; i++) { | |
java.lang.reflect.Method method = methods[i]; | |
int rejectMod = java.lang.reflect.Modifier.ABSTRACT & java.lang.reflect.Modifier.NATIVE & java.lang.reflect.Modifier.PRIVATE & java.lang.reflect.Modifier.PROTECTED & java.lang.reflect.Modifier.STATIC; | |
if ((method.getModifiers() & rejectMod) == 0 && method.getParameterTypes().length <= 0) { | |
String methodname = method.getName(); | |
String propertyname = null; | |
if (methodname.startsWith("get") && methodname.length() > 3) { | |
propertyname = methodname.substring(3); | |
} | |
else if (methodname.startsWith("is") && methodname.length() > 2) { | |
propertyname = methodname.substring(2); | |
} | |
else { | |
continue; | |
} | |
if (propertyname.length() > 0) { | |
String prefix = propertyname.substring(0, 1).toLowerCase(); | |
String suffix = propertyname.substring(1); | |
propertyname = prefix + suffix; | |
} | |
writer.write("console.log('" + propertyname + "=" + method.invoke(object) + "');"); | |
} | |
} | |
writer.write("console.groupEnd('" + groupName + "');</script>"); | |
} | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment