0

这是我的登录控制器包 com.spring.controllers;

import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import org.springframework.ui.ModelMap;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.portlet.ModelAndView;




public class logincontroller {

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

     public String addContact()
         {

             return "login";



     }

    @POST
    @Path("/user/add")
    public Response addUser(
        @FormParam("name") String name,
        @FormParam("age") int age) {

        return Response.status(200)
            .entity("addUser is called, name : " + name + ", age : " + age)
            .build();

    }

}

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"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>Spring3MVC</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

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

         <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-servlet.xml</param-value>
        </init-param> 

        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>

    </servlet-mapping>
</web-app>

spring-servlet.xml

<context:component-scan base-package="com.spring" />
<mvc:annotation-driven />

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

INDEX.JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
 <a href="login.html">Click   
            to enter login  !</a>  

</body>
</html>

登录.jsp

<html>
<body>
    <h1>JAX-RS @FormQuery Testing</h1>

    <form action="rest/user/add" method="post">
        <p>
            Name : <input type="text" name="name" />
        </p>
        <p>
            Age : <input type="text" name="age" />
        </p>
        <input type="submit" value="Add User" />
    </form>

</body>
</html>

收到以下错误警告:在 DispatcherServlet 中找不到带有 URI [/@formparam_fun/login.html] 的 HTTP 请求的映射,名称为“spring”

请求的资源不可用。

我的 index.jsp 在 web-content 中,而 login.jsp 在 web-inf/jsp/login.jsp

4

0 回答 0