2013-11-28 185 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"; 

     } 

} 

可以在这里~~~~~~~~~~~~~~~~~~~~~~,如何删除链接(HREF)

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

这个问题只是贴了我lot.I认为这可能是href.Controller的问题不能把握的HREF

的链接(第二次尝试),但似乎还没有这样的

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毫升

<?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 - /articles/delete/2.html


类型状态报告

消息/articles/delete/2.html

description请求的资源不可用。

+1

你的问题是? – BevynQ

+0

delete -----这不适合被控制器 – Yuxin

+0

所掌握,它看起来没问题,你会得到一个异常吗? – BevynQ

回答

1

HTTP 404错误的原因是没有为您的http请求找到映射。从您的配置看来,您的控制器和请求映射没有得到配置。

你需要一些上下文配置定义调度如下:

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

,然后在servlet-context.xml,您需要定义组件扫描如下扫描您的注解驱动控制器:

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