1

I am trying to Making a simple BBS but I'm encountering following this error,

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet'

I have tried to solve this error many times, but I have failed. How can I solve this error?

here is my web.xml, Controllerand and servlet-context.

my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

 <filter>
  <filter-name>encodingFilter</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>EUC-KR</param-value>
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>encodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- Creates the Spring Container shared by all Servlets and Filters -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <!-- The definition of the Root Spring Container shared by all Servlets 
  and Filters -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/appServlet/servlet-context.xml 
</param-value>
 </context-param>
 <!-- Processes application requests -->
 <servlet>
  <servlet-name>appServlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>
/WEB-INF/spring/appServlet/servlet-context.xml
</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>appServlet</servlet-name>
  <url-pattern>/</url-pattern>
 </servlet-mapping>

</web-app>

my Controller

package com.onj.board;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.board.model.BoardDTO;
import com.board.model.CommentDTO;
import com.board.service.BoardService;
import com.board.util.EncodingHandler;
import com.board.util.PageHandler;

public class BoardMultiController extends MultiActionController {

 private BoardService boardService;
 private PageHandler pageHandler;

 public void setBoardService(BoardService boardService) {
  this.boardService = boardService;
 }

 public void setPageHandler(PageHandler pageHandler) {
  this.pageHandler = pageHandler;
 }

 ModelAndView mav = null;

 public ModelAndView list(HttpServletRequest request,
   HttpServletResponse response) throws Exception {
  mav = new ModelAndView();

  HttpSession session = request.getSession();
  if (session.isNew() == false) {
   session.invalidate();
  }

  List<BoardDTO> list = null;

  String boardListSelect = request.getParameter("boardListSelect");
  String boardListSearchText = request
    .getParameter("boardListSearchText");

  Map<String, Object> searchMap = new HashMap<String, Object>();

  if (boardListSearchText != null) {
   searchMap.put("boardListSearchText",
     EncodingHandler.toKor(boardListSearchText));
   searchMap.put("boardListSelect", boardListSelect);

   mav.addObject("boardListSearchText",
     EncodingHandler.toKor(boardListSearchText));
   mav.addObject("boardListSelect", boardListSelect);
  }

  String pageNumber = request.getParameter("pageNumber");
  int pageNum = 1;
  if (pageNumber != null) {
   pageNum = Integer.parseInt(pageNumber);
  }

  int totalCount = pageHandler.boardAllNumber(searchMap);

  int totalPageCount = pageHandler.boardPageCount(searchMap);

  int startPage = pageHandler.boardStartPage(pageNum);
  int endPage = pageHandler.boardEndPage(pageNum, searchMap);

  List<Object> rowNumberList = new ArrayList<Object>();
  rowNumberList = pageHandler.boardSetPageNumber(pageNum);
  searchMap.put("startRow", rowNumberList.get(0));
  searchMap.put("endRow", rowNumberList.get(1));

  list = boardService.boardList(searchMap);

  mav.addObject("pageNumber", pageNum);
  mav.addObject("boardCount", totalCount);
  mav.addObject("totalPageCount", totalPageCount);
  mav.addObject("startPage", startPage);
  mav.addObject("endPage", endPage);
  mav.addObject("list", list);

  mav.setViewName("list");

  return mav;
 }

 public ModelAndView read(HttpServletRequest request,
   HttpServletResponse response) throws Exception {

  String seq = request.getParameter("seq");
  BoardDTO boardDTO = boardService.readContent(seq);

  HttpSession session = request.getSession();
  session.setAttribute("boardDTO", boardDTO);

  mav.addObject("boardDto", boardDTO);
  mav.addObject("comment", boardService.ListComment(seq));

  mav.setViewName("read");

  return mav;
 }

 public ModelAndView comment(HttpServletRequest request,
   HttpServletResponse response) throws Exception {

  HttpSession session = request.getSession();
  BoardDTO boardDTO = (BoardDTO) session.getAttribute("boardDTO");

  mav = new ModelAndView("redirect:/read.html?seq=" + boardDTO.getSeq());

  CommentDTO commentDTO = new CommentDTO();
  commentDTO.setComment_name(request.getParameter("comment_name"));
  commentDTO.setComment_comm(request.getParameter("comment_comm"));
  commentDTO.setSeq(boardDTO.getSeq());

  boardService.insertComment(commentDTO);

  return mav;
 }

 public ModelAndView write(HttpServletRequest request,
   HttpServletResponse response) throws Exception {
  mav = new ModelAndView("write");
  return mav;
 }

 public ModelAndView writeOk(HttpServletRequest request,
   HttpServletResponse response) throws Exception {

  mav = new ModelAndView("redirect:/list.html");

  MultipartHttpServletRequest mpRequest = (MultipartHttpServletRequest) request;

  String name = request.getParameter("name");
  String passwd = request.getParameter("passwd");
  String title = request.getParameter("title");
  String content = request.getParameter("content");
  MultipartFile file = mpRequest.getFile("file");

  String fileName = file.getOriginalFilename();

  BoardDTO boardDTO = new BoardDTO();

  String fileDir = "D:/upload/";

  byte[] fileData;
  FileOutputStream output = null;

  if (!fileName.equals("")) {
   // 파일 저장
   try {
    fileData = file.getBytes();
    output = new FileOutputStream(fileDir + fileName);
    output.write(fileData);

   } catch (IOException e) {
    e.printStackTrace();
   } finally {
    output.close();
   }
  } else {
   fileName = " ";
  }

  boardDTO.setName(name);
  boardDTO.setPasswd(passwd);
  boardDTO.setTitle(title);
  boardDTO.setContent(content);
  boardDTO.setFilename(fileName);

  boardService.insertBoard(boardDTO);

  return mav;
 }

 public ModelAndView updatePageGo(HttpServletRequest request,
   HttpServletResponse response) throws Exception {

  HttpSession session = request.getSession();
  BoardDTO boardDTO = (BoardDTO) session.getAttribute("boardDTO");

  mav = new ModelAndView("update", "boardDto", boardDTO);

  return mav;
 }

 public ModelAndView update(HttpServletRequest request,
   HttpServletResponse response) throws Exception {

  HttpSession session = request.getSession();

  BoardDTO boardDTO = (BoardDTO) session.getAttribute("boardDTO");

  String name = request.getParameter("name");
  String title = request.getParameter("title");
  String content = request.getParameter("content");
  String seq = boardDTO.getSeq();

  boardDTO.setName(name);
  boardDTO.setTitle(title);
  boardDTO.setContent(content);
  boardDTO.setSeq(seq);

  boardService.updateBoard(boardDTO);

  mav = new ModelAndView("redirect:/read.html?seq=" + seq);

  return mav;
 }

 public ModelAndView delete(HttpServletRequest request,
   HttpServletResponse response) throws Exception {

  mav = new ModelAndView();

  HttpSession session = request.getSession();
  BoardDTO boardDTO = (BoardDTO) session.getAttribute("boardDTO");
  String boardPassword = boardDTO.getPasswd();
  String passwd = request.getParameter("passwd");
  String mas = "";

  if (boardPassword.equals(passwd)) {
   boardService.deleteBoard(boardDTO.getSeq());
   mav.setViewName("redirect:/list.html");
  } else {
   mas = "비밀번호가 일치하지 않습니다.";
   mav.addObject("mas", mas);
   mav.setViewName("redirect:/read.html?seq=" + boardDTO.getSeq());
  }

  return mav;
 }

}

my servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
  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.xsd
  ">

 <!-- DispatcherServlet Context: defines this servlet's request-processing 
  infrastructure -->

 <!-- <context:component-scan base-package="com.onj.board" /> -->

 <!-- Enables the Spring MVC @Controller programming model -->
 <annotation-driven />

 <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
  up static resources in the ${webappRoot}/resources directory -->
 <resources mapping="/resources/**" location="/resources/" />

 <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  destroy-method="close">
  <beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
  <beans:property name="url"
   value="jdbc:oracle:thin:@localhost:1521:ex" />
  <beans:property name="username" value="study" />
  <beans:property name="password" value="study" />
 </beans:bean>

 <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
  in the /WEB-INF/views directory -->
 <beans:bean
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <beans:property name="prefix" value="/WEB-INF/jsp/" />
  <beans:property name="suffix" value=".jsp" />
 </beans:bean>



 <!-- 넘어오는 URL에 따라 컨트롤러에서 실행될 메소드 매핑 -->
 <!-- PropertiesMethodNameResolver는 prop key로 넘어오는 url에 대해 실행할 컨트롤러의 메소드 
  정의 -->
 <beans:bean id="userControllerMethodNameResolver"
  class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
  <beans:property name="mappings">
   <beans:props>
    <beans:prop key="/list.html">list</beans:prop>
    <beans:prop key="/read.html">read</beans:prop>
    <beans:prop key="/comment.html">comment</beans:prop>
    <beans:prop key="/write.html">write</beans:prop>
    <beans:prop key="/writeOk.html">writeOk</beans:prop>
    <beans:prop key="/updatePage.html">updatePageGo</beans:prop>
    <beans:prop key="/update.html">update</beans:prop>
    <beans:prop key="/delete.html">delete</beans:prop>
   </beans:props>
  </beans:property>
 </beans:bean>

 <!-- controller mapping -->
 <beans:bean
  name="/list.html /read.html /comment.html /write.html /writeOk.html /updatePage.html /update.html /delete.html"
  class="com.onj.board.BoardMultiController">
  <beans:property name="methodNameResolver" ref="userControllerMethodNameResolver" />
  <beans:property name="boardService" ref="boardService" />
  <beans:property name="pageHandler" ref="pageHandler" />
 </beans:bean>

</beans:beans>

I need your advice.

Thanks

soorapadman
  • 4,451
  • 7
  • 35
  • 47
S.K. Kang
  • 43
  • 3
  • 7

2 Answers2

1

Try changing the <url-pattern> in your web.xml file to:

<url-pattern>/*</url-pattern>

How are you deploying this application? As board.war?

Also, just to let you know, this is a very ancient way of configuring a Spring MVC application. Spring has some guides available demonstrating the modern approach.

sh0rug0ru
  • 1,596
  • 9
  • 9
  • thanks for your advice I'm deploying this application as java on eclipse and I didn't know it is a very ancient way. – S.K. Kang Sep 30 '15 at 04:54
1

The following items seems to be missing from the code:

1. In servlet-context.xml, add

<context:component-scan base-package="com.onj" />
<mvc:annotation-driven />

Replace <beans:beans .....> with

<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        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.xsd
        http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

2. Add @Controller annotation and @RequestMappings for methods inside it as no controller configuration found in the servlet-context.xml.

@Controller
public class BoardMultiController extends MultiActionController {

Request mapping to list() method:

@RequestMapping(value="/board", method = RequestMethod.GET)
public ModelAndView list(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
James Jithin
  • 10,183
  • 5
  • 36
  • 51