2013-11-28 2 views
0
package net.roseindia.controller; 

import net.roseindia.service.ArticleService; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestParam; 


@Controller 
@RequestMapping("/articles") 
public class DeleteController { 
    @Autowired 
     private ArticleService articleService; 

     @RequestMapping(value="/delete") 
     public String deleteService(@RequestParam("ID") final Integer ids) { 
      System.out.println("hello"); 
      articleService.deleteService(ids); 

      return "redirect:/articles"; 

     } 

} 

여기 ~~~~~~~~~~~~~~~~~~~~~~springMVC, 링크를 삭제하는 방법 (HREF)

<td><a href="/articles/delete.do?ID=${article.articleId}">delete</a></td> 

이 문제가 될 수 있습니다 단지 나에게 lot.I을 잘 접착은 (두 번째 시도) href가

의 링크를 파악할 수없는 href.Controller의 문제가 될 수 있다고 생각하지만, 그것은이

import net.roseindia.service.ArticleService; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestParam; 


@Controller 
@RequestMapping("/articles") 
public class DeleteController { 
    @Autowired 
     private ArticleService articleService; 

     @RequestMapping(value="/delete/{ID}") 
     public String deleteService(@PathVariable("ID") final Integer ids) { 
      System.out.println("hello"); 
      articleService.deleteService(ids); 

      return "redirect:/articles"; 

     } 

} 

    td><a href="/articles/delete/${article.articleId}.html">delete</a></td> 

이런 식으로 작동하지 않습니다 또한 보인다 내 web.x입니다. /articles/delete/2.html


유형 상태 보고서

메시지 /articles/delete/2.html

- ml의

<?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"> 

<servlet> 

<servlet-name>dispatcher</servlet-name> 

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 

<load-on-startup>1</load-on-startup> 

</servlet> 

<servlet-mapping> 

<servlet-name>dispatcher</servlet-name> 

<url-pattern>*.html</url-pattern> 

</servlet-mapping> 

<welcome-file-list> 

<welcome-file>index.jsp</welcome-file> 

</welcome-file-list> 

</web-app> 

Promble는

HTTP 상태 404

설명 요청한 리소스를 사용할 수 없습니다.

+1

귀하의 질문은 무엇입니까? – BevynQ

+0

delete ----- 컨트롤러 – Yuxin

+0

에 의해 파악되는데 작동하지 않습니다. 괜찮아 보이는데 예외가 있습니까? – BevynQ

답변

1

http 요청의 HTTP 404 오류에 대한 이유가 없습니다. 구성에서 컨트롤러 및 요청 매핑이 구성되지 않는 것으로 보입니다. 다음과 같이

당신이 어떤 상황에 맞는 구성으로 디스패처를 정의해야 servlet-context.xml에서 다음

<servlet> 
    <servlet-name>dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

와, 당신은 당신의 주석 구동 컨트롤러를 검색하기 위해 다음과 같이 구성 요소 스캔을 정의해야

<annotation-driven /> 
<context:component-scan base-package="net.roseindia.controller" /> 
관련 문제