Open seulgi9834 opened 3 years ago
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param>
<servlet-name>appServlet</servlet-name>
<load-on-startup>1</load-on-startup>
<servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
<filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
@RequestMapping(value = "saveGet", method = RequestMethod.GET) public String saveGet(HttpServletRequest request, Model model ,@RequestParam(value="title", defaultValue="제목없음") String title ,@RequestParam String content ,@RequestParam(value="viewYn", defaultValue="Y") String viewYn)
public class FormTestVo { private String title; private String content; private String viewYn; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getViewYn() { return viewYn; } public void setViewYn(String viewYn) { this.viewYn = viewYn; } }
@RequestMapping(value = "savePost", method = RequestMethod.POST) public String savePost(HttpServletRequest request, Model model, FormTestVo formTestVo) { String title = formTestVo.getTitle(); String content = formTestVo.getContent(); String viewYn = formTestVo.getViewYn(); System.out.println("제목:"+title); System.out.println("내용:"+content); System.out.println("공개여부:"+viewYn); Map<String, String> map = new HashMap<String,String>(); map.put("title",title); map.put("content", content); map.put("viewYn", viewYn); model.addAttribute("map",map); model.addAttribute(formTestVo); return "form/viewer"; }
강의 때 집중 못해서 놓친 부분이 있었는데,... 해결하는데 도움을 많이 받았습니다...!! 감사합니다.....!
web.xml
Spring Post 한글 깨짐
@RequestParam
Getter/Setter 사용