public static void main(String[] args) {
int[] intArr1 = new int[10]; // size 10, index range from 0 to 9
int []intArr2 = new int[20]; // size 20, index range from 0 to 19
int intArr3[] = new int[20]; // size 20, index range from 0 to 19
}
public static void main(String[] args) {
int[] intArr4 = {1, 2, 3, 4}; // size 4, index range from 0 to 3
int[] intArr5 = {0, 0, 0, 0, 0, 0, 0}; // size 7, index range from 0 to 6
}
public static void main(String[] args) {
int[] intArr1 = new int[10]; // size 10, index range from 0 to 9
int []intArr2 = new int[20]; // size 20, index range from 0 to 19
int intArr3[] = new int[20]; // size 20, index range from 0 to 19
int[] intArr4 = {1, 2, 3, 4}; // size 4, index range from 0 to 3
int[] intArr5 = {0, 0, 0, 0, 0, 0, 0}; // size 7, index range from 0 to 6
System.out.println(Arrays.toString(intArr1));
System.out.println(Arrays.toString(intArr2));
System.out.println(Arrays.toString(intArr3));
System.out.println(Arrays.toString(intArr4));
System.out.println(Arrays.toString(intArr5));
}
private static void lotto() {
final int min = 1;
final int max = 45;
Set<Integer> selected = new HashSet<>();
while(true) {
int randomNumber = (int)(Math.random() * (max - min +1) + min);
if(selected.add(randomNumber)) {
if(selected.size() == 6) {
break;
}
}
}
System.out.println(selected.stream().sorted().collect(Collectors.toList()));
}
์ ๋ฉ์๋๋ฅผ main ํจ์์์ ์คํ์ํค๋ฉด
String getAuthType() The getAuthType() method returns a String object that represents the name of the authentication scheme used to protect the Servlet.
2
boolean isUserInRole(java.lang.String role) The isUserInRole() method returns a boolean value: true if the user is in the given role or false if they are not.
3
String getProtocol() The getProtocol() method returns a String object representing the protocol that was used to send the request. This value can be checked to determine if a secure protocol was used.
4
boolean isSecure() The isSecure() method returns a boolean value representing if the request was made using HTTPS. A value of true means it was and the connection is secure. A value of false means the request was not.
5
Principle getUserPrinciple() The getUserPrinciple() method returns a java.security.Principle object that contains the name of the current authenticated user.
<%@ page import="java.io.*,java.util.*" %>
<html><head><title>Page Redirection</title></head><body><center><h1>Page Redirection</h1></center><%// New location to be redirectedString site =newString("http://www.naver.com");
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", site);
%>
</body></html>
public Object getAttribute(String name) This method returns the object bound with the specified name in this session, or null if no object is bound under the name.
2
public Enumeration getAttributeNames() This method returns an Enumeration of String objects containing the names of all the objects bound to this session.
3
public long getCreationTime() This method returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
4
public String getId() This method returns a string containing the unique identifier assigned to this session.
5
public long getLastAccessedTime() This method returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT.
6
public int getMaxInactiveInterval() This method returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.
7
public void invalidate() This method invalidates this session and unbinds any objects bound to it.
8
public boolean isNew( This method returns true if the client does not yet know about the session or if the client chooses not to join the session.
9
public void removeAttribute(String name) This method removes the object bound with the specified name from this session.
10
public void setAttribute(String name, Object value) This method binds an object to this session, using the name specified.
11
public void setMaxInactiveInterval(int interval) This method specifies the time, in seconds, between client requests before the servlet container will invalidate this session.
<%@ page import="java.io.*,java.util.*" %>
<%// Get session creation time.Date createTime =newDate(session.getCreationTime());// Get last access time of this web page.Date lastAccessTime =newDate(session.getLastAccessedTime());String title ="Welcome Back to my website";Integer visitCount =newInteger(0);String visitCountKey =newString("visitCount");String userIDKey =newString("userID");String userID =newString("ABCD");// ์ฒ์ ์ ์ํ ๋ฐฉ๋ฌธ์๋ผ๋ฉด ์ธ์ ์ ์์ฑํฉ๋๋ค.if(session.isNew()){
title ="Welcome to my website";
session.setAttribute(userIDKey, userID);
session.setAttribute(visitCountKey, visitCount);}
visitCount =(Integer)session.getAttribute(visitCountKey);
visitCount = visitCount +1;
userID =(String)session.getAttribute(userIDKey);
session.setAttribute(visitCountKey, visitCount);
%>
<html><head><title>Session Tracking</title></head><body><center><h1>Session Tracking</h1></center><tableborder="1"align="center"><trbgcolor="#949494"><th>Session info</th><th>Value</th></tr><tr><td>id</td><td><%out.print( session.getId()); %></td></tr><tr><td>Creation Time</td><td><%out.print(createTime); %></td></tr><tr><td>Time of Last Access</td><td><%out.print(lastAccessTime); %></td></tr><tr><td>User ID</td><td><%out.print(userID); %></td></tr><tr><td>Number of visits</td><td><%out.print(visitCount); %></td></tr></table></body></html>
public void setDomain(String pattern) This method sets the domain to which cookie applies, for example tutorialspoint.com.
2
public String getDomain() This method gets the domain to which cookie applies, for example tutorialspoint.com.
3
public void setMaxAge(int expiry) This method sets how much time (in seconds) should elapse before the cookie expires. If you don't set this, the cookie will last only for the current session.
4
public int getMaxAge() This method returns the maximum age of the cookie, specified in seconds, By default, -1 indicating the cookie will persist until browser shutdown.
5
public String getName() This method returns the name of the cookie. The name cannot be changed after creation.
6
public void setValue(String newValue) This method sets the value associated with the cookie.
7
public String getValue() This method gets the value associated with the cookie.
8
public void setPath(String uri) This method sets the path to which this cookie applies. If you don't specify a path, the cookie is returned for all URLs in the same directory as the current page as well as all subdirectories.
9
public String getPath() This method gets the path to which this cookie applies.
10
public void setSecure(boolean flag) This method sets the boolean value indicating whether the cookie should only be sent over encrypted (i.e. SSL) connections.
11
public void setComment(String purpose) This method specifies a comment that describes a cookie's purpose. The comment is useful if the browser presents the cookie to the user.
12
public String getComment() This method returns the comment describing the purpose of this cookie, or null if the cookie has no comment.
<%// Create cookies for first and last names. Cookie firstName =newCookie("first_name",
request.getParameter("first_name"));Cookie lastName =newCookie("last_name",
request.getParameter("last_name"));// Set expiry date after 24 Hrs for both the cookies.
firstName.setMaxAge(60*60*24);
lastName.setMaxAge(60*60*24);// Add both the cookies in the response header.
response.addCookie( firstName );
response.addCookie( lastName );
%>
<html><head><title>Setting Cookies</title></head><body><center><h1>Setting Cookies</h1></center><ul><li><p><b>First Name:</b><%= request.getParameter("first_name")%>
</p></li><li><p><b>Last Name:</b><%= request.getParameter("last_name")%>
</p></li></ul></body></html>
<html><body><formaction="main.jsp"method="GET">
First Name: <inputtype="text"name="first_name"><br/>
Last Name: <inputtype="text"name="last_name"/><inputtype="submit"value="Submit"/></form></body></html>
<html><head><title>Reading Cookies</title></head><body><center><h1>Reading Cookies</h1></center><%Cookie cookie =null;Cookie[] cookies =null;// Get an array of Cookies associated with this domain
cookies = request.getCookies();if( cookies !=null){out.println("<h2> Found Cookies Name and Value</h2>");for(int i =0; i < cookies.length; i++){
cookie = cookies[i];out.print("Name : "+ cookie.getName()+", ");out.print("Value: "+ cookie.getValue()+" <br/>");}}else{out.println("<h2>No cookies founds</h2>");}
%>
</body></html>
<html><head><title>Reading Cookies</title></head><body><center><h1>Reading Cookies</h1></center><%Cookie cookie =null;Cookie[] cookies =null;// Get an array of Cookies associated with this domain
cookies = request.getCookies();if( cookies !=null){out.println("<h2> Found Cookies Name and Value</h2>");for(int i =0; i < cookies.length; i++){
cookie = cookies[i];if((cookie.getName()).compareTo("first_name")==0){cookie.setMaxAge(0);
response.addCookie(cookie);out.print("Deleted cookie: "+
cookie.getName()+"<br/>");}out.print("Name : "+ cookie.getName()+", ");out.print("Value: "+ cookie.getValue()+" <br/>");}}else{out.println("<h2>No cookies founds</h2>");}
%>
</body></html>