String(1)

coc·2023년 8월 24일
0

1) String

1. Programming 에서 문자열을 다루는 것은 byte 와 char 뿐이다.

2. 본래 문자열(string)은 char 의 배열(array)이다.

3. Java 에서는 문자열을 다루기 위한 String 이라는 class를 만들게 된다.

2) 쿼터

1. 단일 쿼터 ''

2. 더블 쿼터 ""

3) String calss

- String class 는 문자열과 관련된 많은 기능을 제공해 준다.

- String class 알아야 할 기능

String 코드

String controller

package kr.co.gudi.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/") //다 받아준다는 뜻이다.
public class HomeController extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
		String str1 = "hello String";//문자열1
		String str2 = new String("hello String");//문자열2
		//char[] ch = new char [] {'h','e','l','l','o','s','t','r','i','n','g'};
		String str3 = new String(new char [] {'h','e','l','l','o','s','t','r','i','n','g'});//문자열3
		
		System.out.println(str1);
		System.out.println(str2);
		System.out.println(str3);
		
		req.setAttribute("str1", str1); 
		req.setAttribute("str2", str2);
		req.setAttribute("str3", str3);
		//404의 이유
		//1.원하는 요청이 존재하지 않을 경우
		//2.도착해야할 페이지가 존재하지 않을 경우
		
		RequestDispatcher dis = req.getRequestDispatcher("main.jsp");//보낸다
		dis.forward(req, resp);
	}

	

}

Main jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
</head>
<body>
<h3>${str1}</h3> 
<h3>${str2}</h3>
<h3>${str3}</h3>
</body>
</html>

결과물

profile
시작

0개의 댓글