Posts

Showing posts from August, 2023

[JAVA] Improper Resource Releases

Image
  It's because we didn't finally release the resources It corresponds to a violation of the web vulnerability. ex) Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; try { // conn , pstmt , rs code }catch(NullPointerException e){ finally{ if(rs!=null){rs.close();} if(pstmt!=null){pstmt.close();} if(conn!=null){conn.close();} } 😀 Thank you !! 감사합니다 !!

[JAVA] Error Message Information Disclosure

Image
Errors or error information should not be exposed to the console or on the screen. Use simple phrases only if necessary. Error information or system information should not be printed on the console or browser, but should be logged or printed in simple phrases if necessary Example of system data information disclosure (removal target code) Syste m.out.println(e.getMessage());, System.out.println(e);, e.printStackTrace();, out.println(e.getMessage()); Wrong ex) }catch(NullPointerException e){ System.out.println("Error : "+e); } } Right ex) }catch(NullPointerException e){ logger.error("ERROR-01 NullPointerException"); OR System.out.println("ERROR-01 NullPointerException"); } } 😀 Thank you !! 고마워 !!

[JAVA] Improper Exception Handling

Image
Throwable,Exception,RuntimeException must be that  It should not be widely held, but specific exceptions such as FileNotFoundException, SQLException, IOException, ClassNotFoundEXception, etc. should be handled  !! Wring ex) } catch(Exception e) { logger.error("ERROR-01 Exception"); } Right ex) } catch( SQLException e) { logger.error("ERROR-01 SQLException"); } 😀 Thank you!! 고마워!!

[JAVA] Creating a Star Pyramid

Image
class Star{ public static void main(String[] args){ for(int a=1; a<10; a=a+2){ // 1 3 5 7 9 for(int b=10; b>a; b=b-2){ // 10 8 6 4 2  System.out.print(" "); } for(int c=0; c<a; c=c+1){ // 0 1 2 3 4 5 6 7 8  System.out.print("*"); }     System.out.println(); } } } an) 😀 Thank you!! 고마워!!

[JAVA] Convert to int to String

Image
int e = 1000; String str = String.valueOf(e);   System.out.println(str);  result : 1000 😀 Thank you!! 고마워!!

[JAVA] getting of Date Difference

Image
<%@ page import="java.text.SimpleDateFormat"%> <%@ page import="java.util.Date"%> Date todayShow1 = new Date(); String chkDateShow1 = ""; SimpleDateFormat formatShow1;  formatShow1 = new SimpleDateFormat("yyyyMMdd"); chkDateShow1 = formatShow1.format(todayShow1); String date1="20230504"; String date2=chkDateShow1; String date3="20230915"; DateFormat format = new SimpleDateFormat("yyyyMMdd"); Date d1 = format.parse( date1 ); Date d2 = format.parse( date2 ); Date d3 = format.parse( date3 ); long Sec = (d1.getTime() - d2.getTime()) / 1000; //  long Min = (d1.getTime() - d2.getTime()) / 60000; //  long Hour = (d1.getTime() - d2.getTime()) / 3600000; //  long Days = Sec / (24*60*60); //  long Sec3 = (d3.getTime() - d2.getTime()) / 1000; //  long Min3 = (d3.getTime() - d2.getTime()) / 60000; //  long Hour3 = (d3.getTime() - d2.getTime()) / 3600000; //  long Days3 = Sec3 / (24*60*60); //  <script> $(docume...

[JAVA] use contains function when checking whether JAVA Java string is included

Image
When checking for Java string inclusion ex) String str = "contains test"; System.out.println( str.contains("contains") );  // true System.out.println( str.contains("what") );  // false System.out.println( str.contains("TEST") );  // false System.out.println( str.contains("test") );  // true 😀 Thank you!! 감사합니다!!

[JAVA] out.print - alert

Image
Show script alert with Java out.print   <% out.println("<script>alert('go back~^^');</script>"); out.println("<script>window.close(); history.back();</script>"); %> 😀 Thank you!! 고마워!!

[JAVA] When two different lists are displayed sequentially

Image
For example, one list brings information on Instagram and the other YouTube There are times when you have to express it like Instagram1/YouTube1/Instagram2/YouTube2 Of course, the two lists cannot be retrieved from one place.   List<Map<String,Object>> listA = null; List<Map<String,Object>> listB = null; listA = jdbcTemplate.query(sqlA, new Db()); listB = jdbcTemplate.query(sqlB, new Db()); <% int cntAll = 1; int indexYoutube = 0; int indexFaceBook = 0; for( int indexsAll = 0; indexsAll < 4; indexsAll++ ) { // all - insta and youtube if( listA.size() > 0 && cntAll<=listA.size() ) { for( int indexs = indexYoutube; indexs < cntAll; indexs++ ) {  %> <li> <div class="youtubebox"> // youtube show </div> </li> <% indexYoutube++; } } if( listB.size() > 0 && cntAll<=listB.size() ) { for(int indexs2=indexFaceBook; indexs2<cntAll; indexs2++){ // 0 , 0 < 1 %> <li> <div cla...

[JAVA] trinomial operator Example

Image
String byunSoo = request.getParameter("year") != null ? currentYear : ""; 😀 Thank you!! 감사합니다!!

[JAVA] Java nested for statement example

Image
class A{ public static void main(String[] args){ for(int a=1; a<5; a=a+1){ System.out.print(a); for(int b=0; b<10; b=b+1){ System.out.print("*"); } System.out.println(); } } }  resulit 😀 Thank you!! 고마워!!

[JAVA] Excel multi-sheet upload poi 4.1.2

Image
The Excel file extension tested is xlxs I know that poi 4.1.2 version is possible for both xls and xlxs, but the test was conducted with xlxs First, pom.xml. Defendency <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> JSP <form id="uploadFrm" method="post" action="<c:url value='/excelUpload.do'/>" enctype="multipart/form-data"> <input type="file" name="upFile" id="upFile" accept=".xlsx, .xls" class="buttonFileup"/> <input type="button" onclick="uploadExcel()" class="button03" value="엑셀 파일 업로드"> </form> Of course, enable type is "multipart...