【问题标题】:Spring MVC- Page Not Found errorSpring MVC-找不到页面错误
【发布时间】:2013-05-04 16:35:14
【问题描述】:

我正在尝试实现 muliple file upload 教程的变体,但在运行应用程序时遇到了问题。

我使用模板在 Eclipse 中创建了一个 Spring MVC 项目。

控制器已经实现

@Controller
public class FileUploadController {

    @RequestMapping(value = "/show", method = RequestMethod.GET)
    public String displayForm() {
       return "uploadForm";
    }

    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public String save(@ModelAttribute("uploadForm") FileUploadForm uploadForm, Model map) {
       //get file name and copy to server location
       return "uploadSuccess"
    }

其中uploadFormuploadSuccessViews 中的JSP 页面

我的 web.xml 文件定义为

<display-name>SampleFileUpload</display-name>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

spring-servlet.xml 文件定义为

<context:annotation-config />
<context:component-scan base-package = "com.jasonjohns.spring.fileupload.controller" />


<bean id = "multipartResolver" class = 
    "org.springframework.web.multipart.commons.CommonsMultipartResolver" />

<bean id = "jspViewResolver" class = 
    "org.springframework.web.servlet.view.InternalResourceViewResolver">

    <property name = "viewClass" value = 
    "org.springframework.web.servlet.view.JstlView" />
    <property name = "prefix" value = "/WEB-INF/views/" />
    <property name = "suffix" value = ".jsp" />     
</bean>

但是,当我启动应用程序时,没有发现任何错误,除了服务器返回 404 错误,即使我转到 localhost:8080/SampleFileUpload/show.html。你猜这是一个控制器错误,但我不明白它背后的原因。

【问题讨论】:

  • 是说show.html不可用还是uploadForm.jsp

标签: spring-mvc


【解决方案1】:

您是否尝试从以下位置更改映射:

@RequestMapping(value = "/show", method = RequestMethod.GET)

@RequestMapping(value = "/show.html", method = RequestMethod.GET)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    相关资源
    最近更新 更多