弹簧mvc代码当我点击链接时给出404错误

时间:2016-06-09 08:24:52

标签: spring spring-mvc

的index.jsp:

 <a href="hello">click</a>`

HelloWorldController:

package com.javatpoint;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloWorldController

{



@RequestMapping("/hello")
public ModelAndView  helloworld()
{
    String message="Hello Spring MVC ";
    return new ModelAndView("hellopage","message",message);
}

}

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>springmvc</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<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>/</url-pattern>
    </servlet-mapping>
</web-app>

弹簧servlet.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xmlns:p="http://www.springframework.org/schema/p"  
xmlns:context="http://www.springframework.org/schema/context"  
xsi:schemaLocation="http://www.springframework.org/schema/beans  
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="com.javatpoint"/>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>
</beans>

enter image description here

hellopage.jsp:

Message is: ${message}

in the image i have shown the directories so please check it as well in case

1 个答案:

答案 0 :(得分:0)

尝试使用此

> y <- as.matrix(Y)
> data <- list(x, y=y)
> sgl_small <- cvSGL(data, groups, type="linear")

由于控制器使用URL“/ hello”

进行映射