[문제1]
Project : Chapter06_1
Package : com.controller
Class : SumController
Package : com.bean
Class : SumDTO
Foler : sum
File : input.jsp
result.jsp
스프링 설정 파일
/WEB-INF/dispatcher-servlet.xml → /WEB-INF/dispatcher-config.xml
[실행결과]
http://localhost:8080/Chapter06_1/input.do
input.jsp ---------> result.jsp
X : ㅁ 25 + 36 = xx
Y : ㅁ
계산(submit)
result.do
-------------------------------------------------------------
프로젝트 생성
web.xml 생성
서블릿 작성
dispatcher-config.xml 만들기
콘트롤러 생성
주소확인
콘트롤러
sum폴더 생성
input.jsp 생성
result.jsp 생성
---------------------------------------------------------------------
>>> web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Chapter06_1</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--
스프링 설정 파일 :
/WEB-INF/dispatcher-servlet.xml
WAC의 이름 또는 위치를 바꾸고 싶을때
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
>>> dispatcher-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="prefix" value="/view/"></property> // 많이 안씀 -->
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="SumController" class="com.controller.SumController"></bean>
</beans>
>>> controller(com.controller-SumController.java)
package com.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SumController { //POJO형식 -> 순수한 자기만의 클래스 (extends implement 모두 안해줌)
//http://localhost:9090/Chapter06_1/input.do
@RequestMapping(value="/input.do", method = RequestMethod.GET) // get방식
public ModelAndView input() {
ModelAndView mav = new ModelAndView();
mav.setViewName("/sum/input");
return mav;
}
@RequestMapping(value="/result.do", method = RequestMethod.GET) // get방식
public ModelAndView result() {
ModelAndView mav = new ModelAndView();
mav.setViewName("/sum/result");
return mav;
}
}
>>>>>> input.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="result.do" method=get>
<!-- //<form action="http://localhost:9090/Chapter06_1/result.do" method=get> -->
<table border="1" align="center">
<tr>
<td> X<input type=text name="x" > </td>
</tr>
<tr>
<td> Y<input type=text name="y"> </td>
</tr>
<tr>
<td align="center"> <input type=submit value="result"> <input type=reset value="취소" > </td>
</tr>
</table>
</form>
</body>
</html>
>>>>> result.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
${param.x } + ${param.y } = ${param.x + param.y}
</body>
</html>
>>>> 결과
http://localhost:9090/Chapter06_1/input.do
'JAVA 개발 공부 정보' 카테고리의 다른 글
자바수업-스프링-Chapter04-스프링JDBC (0) | 2018.02.22 |
---|---|
자바수업-스프링 Chapter06-스프링MVC (0) | 2018.02.22 |
spring- 파일 다운만 되는 소스 (0) | 2018.02.02 |
[개발교육] 자바 jsp 기초 - 8(output.jsp) (0) | 2018.01.15 |
[개발교육] 자바 jsp 기초 - 8(InputHtml) (0) | 2018.01.15 |