반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 스프링게시판insert
- 게시판insert
- url설정
- 톰캣시작페이지설정
- 게시판목록조회
- insert할글깨짐
- 전자정부프레임워크 double-submit
- 한글깨짐해결방법
- 컨트롤러url
- insert 중복방지
- 이클립스데이터베이스연결
- 게시판만들기
- 게시판상세보기
- 스프링게시판목록조회
- 이클립스db연결
- 스프링프로젝트
- 스프링게시판상세보기
- HTML
- 자바스크립트
- Could not create the java Virtual Machine
- 톰캣9.0다운로드
- mysqlinsert한글깨짐
- 스프링게시판등록
- dataSource설정
- mybatis연결
- oracle
- Java
- 스프링게시판만들기
- 저장할때한글깨짐
- double-submit
Archives
- Today
- Total
하루의 일상💜
[게시판만들기] 컨트롤러 통하여 .do로 jsp 열기/jsp:forward 본문
반응형
1. web.xml 설정
서블릿을 관리할 수 있는 경로를 web.xml에 설정해준다.
아래와 같이 설정완료 후 써준 경로와 같이 폴더만들고 xml 파일도 같이 생성한다.
/WEB-INF/config/springmvc/dispatcher-servlet.xml
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>haru</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/springmvc/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
2. dispatcher-servlet.xml 설정
아래와 같이 폴더와 xml 파일을 생성 해 준다.
dispatcher-servlet.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="haru">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="1"
p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
</beans>
<context:component-scan base-package="haru"> 는 "haru"라는 패키지의 어노테이션을 인식한다는 설정이다.
컨트롤러나 서비스 등을 설정할 수 있다.( ex) @Controller, @Service)
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>는 /WEB-INF/jsp/하위 폴더에 있는 .jsp로 끝나는 파일을 인식 할 수 있게 설정한 코드이다.
3. 컨트롤러 url 설정
현재 처음페이지를 index.jsp로 설정하였기 때문에 수정이 필요하다.
index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<jsp:forward page="/index.do"/>
기존의 index.jsp를 위처럼 변경해준다. forward는 컨트롤러 url 로 바로 연결해준다.
/haru/src/main/java/haru/com/bbs/web/BbsController.java 경로에 컨트롤러를 생성해준다.
BbsController.java
package haru.com.bbs.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class BbsController {
@RequestMapping(value = "/index.do")
public String main() throws Exception {
return "main";
}
}
return으로 main이라는 jsp를 불러오게 될 것이다.
/jsp 밑에 main.jsp 페이지를 생성해준다.
main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div>메인페이지<div>
</body>
</html>
메인페이지 불러오기 완료!
반응형
'전자정부프레임워크' 카테고리의 다른 글
[게시판만들기] 게시글목록 조회하기 (1) | 2024.02.29 |
---|---|
[게시판만들기] MyBatis, MySQL DB연결 (0) | 2024.02.29 |
[게시판만들기] 톰캣 프로젝트 실행시 시작페이지 설정/포트번호입력하여 jsp열기 (1) | 2024.02.14 |
[게시판만들기] 이클립스 톰캣 설정/톰캣 9.0 다운로드 (0) | 2024.02.14 |
[게시판만들기] Eclipse 이클립스 프로젝트 생성하기 (0) | 2024.02.14 |