2017-07-18 52 views
-1

enter image description here[404]不能的doGet()來的doPost()。(在board_write)

我想連接到 'boardWrite.jsp' 點擊時有色(寫入)按鈕。 (使用命令) 其他功能表現不錯,但只有這是錯誤的。

錯誤消息是404這樣的

enter image description here

當我嘗試調試,我發現,它不能從doGet()doPost()在BoardServlet.java以下。

這裏是我的代碼...

由於我是新手,我的問題看起來荒謬的,我知道。 但現在對我來說很重要..然後,我希望我能在這裏得到幫助。 我做我的最好..

***1. boardlist.jsp*** 

    `<body> 
     <div id="wrap" align="center"> 
     <h1>게시글 리스트</h1> 
     <table class="list"> 
      <tr> 
      <td colspan=5 style="border:white; text-align:right"> 
       <a href = "BoardServlet?command=board_write_form">게시글등록</a> 
      </td> 
      </tr> 
      <tr> 
      <th>번호</th> 
      <th>제목</th> 
      <th>작성자</th> 
      <th>작성일</th> 
      <th>조회</th> 

      </tr> 


      <c:forEach var="board" items="${boardList}"> 
      <tr class = "record"> 
      <td>${board.num}</td> 
      <td><a href="BoardServlet?command=board_view&num=${board.num}">${board.title}</a></td> 
      <td>${board.name}</td> 
      <td><fmt:formatDate value="${board.writedate}" /></td> 
      <td>${board.readcount}</td> 
      </tr> 


      </c:forEach> 

     </table> 


     </div>` 

    2. BoardServlet.java 
package com.board.controller; 

import java.io.IOException; 
import javax.servlet.ServletException; 
import javax.servlet.annotation.WebServlet; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

import com.board.controller.action.Action; 

/** 
* Servlet implementation class BoardServlet 
*/ 
@WebServlet("/BoardServlet") 
public class BoardServlet extends HttpServlet {  //컨트롤러 클래스 
    private static final long serialVersionUID = 1L; 

    /** 
    * @see HttpServlet#HttpServlet() 
    */ 
    public BoardServlet() { 
     super(); 
     // TODO Auto-generated constructor stub 
    } 

    /** 
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 
    */ 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     // TODO Auto-generated method stub 
     String command = request.getParameter("command"); 
     System.out.println("BoardServlet에서 요청을 받음을 확인 :"+command); 
     ActionFactory af = ActionFactory.getInstance(); 
     Action action = af.getAction(command); 
     if(action!=null){ 
      action.execute(request, response); 

     } 
    } 

    /** 
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 
    */ 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     // TODO Auto-generated method stub 
     request.setCharacterEncoding("UTF-8"); 
     doGet(request, response); 
    } 

} 


    ***2.ActionFactory.java*** 

    `package com.board.controller; 

    import com.board.controller.action.Action; 
    import com.board.controller.action.BoardListAction; 
    import com.board.controller.action.BoardViewAction; 
    import com.board.controller.action.BoardWriteAction; 
    import com.board.controller.action.BoardWriteFormAction; 

    public class ActionFactory { 
     private static ActionFactory instance = new ActionFactory(); 

     private ActionFactory(){ 
      super(); 
     } 

     public static ActionFactory getInstance(){ 
      return instance; 
     } 

     // 요청된 명령어별로 분기 처리하는 메서드 

     public Action getAction(String command){ 
      Action action = null; 
      System.out.println("ActionFactory:"+command); 

      if(command.equals("board_list")){ 
       action = new BoardListAction(); // 객체를 생성했다는 말은 => 해당 객체의 클래스를 찾아간다는 의미로 받아들여도 된다. 
      }else if(command.equals("board_view")){ 
       action = new BoardViewAction(); 
      }else if(command.equals("board_write_form")){ 
       action = new BoardWriteFormAction(); 
      }else if(command.equals("board_write")){ 
       action = new BoardWriteAction(); 
      } 
      return action; 
     } 

    }` 

    3. BoardDAO.java 

     ' public class BoardDAO { 

     private BoardDAO(){} 

     private static BoardDAO instance = new BoardDAO(); 

     public static BoardDAO getInstance(){ 
      return instance; 
     } 

     public List<BoardVO> selectAllBoard(){ 
      String sql = "select * from board order by num desc"; 
      List<BoardVO> list = new ArrayList<BoardVO>(); 
      Connection conn = null; 
      Statement stmt = null; 
      ResultSet rs = null; 

      try{ 
       conn=DBManager.getConnection(); 
       stmt = conn.createStatement(); 
       rs = stmt.executeQuery(sql); 

       while(rs.next()){ 
        BoardVO bVo = new BoardVO(); 
        bVo.setNum(rs.getInt("num")); 
        bVo.setTitle(rs.getString("title")); 
        bVo.setName(rs.getString("name")); 
        bVo.setPass(rs.getString("pass")); 
        bVo.setContent(rs.getString("content")); 
        bVo.setReadcount(rs.getInt("readcount")); 
        bVo.setWritedate(rs.getTimestamp("writedate")); 
        list.add(bVo); 
       } 

      }catch(SQLException e){ 
       e.printStackTrace(); 
      }finally{ 
       DBManager.close(rs, stmt, conn); 
      } 

      return list; 
     } 

     // 글 내용의 readcount 값 증가 

     public void updateReadCount(String num){ 
      String sql = "update board set readcount=readcount+1 where num=?"; 
      Connection conn = null; 
      PreparedStatement pstmt = null; 

      try{ 
       conn = DBManager.getConnection(); 
       pstmt = conn.prepareStatement(sql); 
       pstmt.setString(1, num); 
       pstmt.executeUpdate(); 


      }catch(SQLException e){ 
       e.printStackTrace(); 
      }finally{ 
       DBManager.close(pstmt, conn); 
      } 
     } 

     // 게시판 글 상세 내용 보기 

     public BoardVO selectBoardByNum(String num){ 
      String sql = "select * from board where num=?"; 
      BoardVO bVo = null; 
      Connection conn = null; 
      PreparedStatement pstmt = null; 
      ResultSet rs = null; 

      try{ 
       conn = DBManager.getConnection(); 
       pstmt = conn.prepareStatement(sql); 
       pstmt.setString(1, num); 
       rs = pstmt.executeQuery(); 

       if(rs.next()){ 
        bVo = new BoardVO(); 

        bVo.setNum(rs.getInt("num")); 
        bVo.setName(rs.getString("name")); 
        bVo.setTitle(rs.getString("title")); 
        bVo.setPass(rs.getString("pass")); 
        bVo.setEmail(rs.getString("email")); 
        bVo.setTitle(rs.getString("title")); 
        bVo.setContent(rs.getString("content")); 
        bVo.setWritedate(rs.getTimestamp("writedate")); 
        bVo.setReadcount(rs.getInt("readCount")); 
       } 

      }catch(Exception e){ 
       e.printStackTrace(); 
      }finally{ 
       DBManager.close(rs, pstmt, conn); 
      } 
      return bVo; 
     } 

     //게시글 등록 
     public void insertBoard(BoardVO bVo){ 
      String sql = "insert into board(" 
        + "num, name, email, pass, title, content)" 
        + "values(board_seq.nextVal, ?, ?, ?, ?, ?)"; 
      Connection conn = null; 
      PreparedStatement pstmt = null; 

      try{ 
       conn = DBManager.getConnection(); 
       pstmt = conn.prepareStatement(sql); 

       pstmt.setString(1, bVo.getName()); 
       pstmt.setString(2, bVo.getEmail()); 
       pstmt.setString(3, bVo.getPass()); 
       pstmt.setString(4, bVo.getTitle()); 
       pstmt.setString(5, bVo.getContent()); 
       pstmt.executeUpdate(); 

      }catch(SQLException ex){ 
       ex.printStackTrace(); 
      }finally{ 
       DBManager.close(pstmt, conn); 
      } 
     } 


    }' 

    ***4. BoardWriteFormAction.java*** 

    public class BoardWriteFormAction implements Action { 

     @Override 
     public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
      // TODO Auto-generated method stub 

      String url = "\board\boardWrite.jsp"; 
      RequestDispatcher dispatcher = request.getRequestDispatcher(url); 
      dispatcher.forward(request, response); 
     } 

    } 
+0

看起來像你沒有正確部署這個jsp,因爲錯誤是提到'%08oard%08oardWrite.jsp'這與'BoardServlet'無關。 –

回答

-1

既然你得到一個404錯誤,我懷疑你的servlet未正確在web.xml映射。檢查一下。如果您不知道這意味着什麼,那麼Google如何爲Tomcat上的servlet或JSP應用程序設置web.xml。簡而言之,這是將請求URL映射到您的servlet類。如果你沒有這樣做,那麼服務器不知道「BoardServlet」是什麼。

此外,您不說,但是您的servlet打印輸出到Catalina控制檯的doGet方法中通過System.out.printl的日誌語句?如果是,那麼你知道你的servlet正在被調用。如果沒有,那麼我再次建議您確保您的servlet在web.xml中正確映射。

最後,您應該使用java.util.logging(或其他日誌記錄解決方案)在您的服務器上記錄代碼。雖然System.out.printl將在Tomcat中工作並寫入控制檯,但當您的服務器不是您的開發計算機時,這將不起作用。

+0

感謝你的真誠的評論。我仍在努力 –

相關問題