请求不由DispatcherServlet处理" HTTP状态404 - /Mvcvalid/displayForm.html(请求的资源不可用)"

时间:2014-07-02 07:08:56

标签: java hibernate validation spring-mvc tomcat7

当我在Tomcat 7.0服务器上运行我的应用程序时,我的 index.jsp 文件被执行,如果我点击 LOGIN(href) loginPage .jsp 它不会被执行。

我的TOMCAT中出现了以下错误,因为请求的资源不可用。我已经搜索了很多但是仍然无法摆脱这个。

实际上是尝试使用 java4sController.java和UserDetails.java类来验证我的 loginPage.jsp 文件。

我的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/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">

<welcome-file-list>
   <welcome-file>index.html</welcome-file>
</welcome-file-list>


<servlet>
   <servlet-name>java4s</servlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>
 <servlet-mapping>
   <servlet-name>java4s</servlet-name>
   <url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

的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>SRI PREM VALIDATION</title>
</head>
<body>
<font face="verdana" size="2">
   <a href="displayForm.html">Login..</a>
</font>
</body>
</html>

java4s-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"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/mvc

        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

<context:component-scan base-package="java4s" />

    <mvc:annotation-driven />

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

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
       <property name="basename" value="props" />
    </bean>

</beans>

java4sController.java

package java4s;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class Java4sController {    

        @RequestMapping(value="/displayForm", method=RequestMethod.GET)
        public String helloWorld(ModelMap model) {
        UserDetails ud = new UserDetails();
         ud.setUser("");
         ud.setEmail("");
        model.addAttribute("userDetails",ud);
        return "loginPage"; 
    }


        @RequestMapping("/login")
        public String loginCheck(@Valid UserDetails userDetails, BindingResult result, ModelMap model) {
            if (result.hasErrors()) {
                return "loginPage";
            } else {
                model.addAttribute("lfobj", userDetails);
                return "success";
            }
        }

}

UserDetails.java

  

包java4s; import javax.validation.constraints.Size;进口   org.hibernate.validator.constraints.Email;进口   org.hibernate.validator.constraints.NotEmpty;进口   org.hibernate.validator.constraints.URL; public class UserDetails {

    @NotEmpty
    private String user;

    @NotEmpty
    @Email
    private String email;        

    @NotEmpty(message = "Phone should not be blank.")
    @Size(min = 10,max = 10)
    private String phone;

    @NotEmpty(message = "Enter your blog URL")
    @URL
    private String blog;

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getBlog() {
        return blog;
    }

    public void setBlog(String blog) {
        this.blog = blog;
    }   }

我的loginPage.jsp

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<html>
<head>
     <title>Spring3Example</title>
<style>
  .error {
      color: #EF1313;
      font-style: italic;
  }
</style>
</head>
<body>

<form:form action="login.html" commandName="userDetails">
<table>
<tr>
    <td><font face="verdana" size="2px">User</font></td>
    <td>:</td>
    <td>
    <font face="verdana" size="2">
    <form:input path="user" /> <form:errors path="user"></form:errors>
    </font>
    </td>
</tr>
<tr>
    <td><font face="verdana" size="2px">Email</font></td>
    <td>:</td>
    <td>
    <font face="verdana" size="2">
    <form:input path="email" /> <form:errors path="email"></form:errors>
    </font>
    </td>
</tr>
<tr>
    <td><font face="verdana" size="2px">Phone</font></td>
    <td>:</td>
    <td>
    <font face="verdana" size="2">
    <form:input path="phone" /> <form:errors path="phone"></form:errors>
    </font>
    </td>
</tr>
<tr>
    <td><font face="verdana" size="2px">Blog</font></td>
    <td>:</td>
    <td>
    <font face="verdana" size="2">
    <form:input path="blog" /> <form:errors path="blog"></form:errors>
    </font>
    </td>
</tr>
<tr>
    <td>
    <input type="submit" value="Submit" />
    </td>
</tr>
</table>
</form:form>
</body>
</html>

我的Tomcat7.0出错。 。

   HTTP Status 404 - /Mvcvalid/displayForm.htm

--------------------------------------------------------------------------------

type Status report

message /Mvcvalid/displayForm.htm

description The requested resource is not available.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.42

1 个答案:

答案 0 :(得分:0)

尝试删除UserDetails作为

方法的参数
@RequestMapping(value="displayForm", method=RequestMethod.GET)
    public String helloWorld(UserDetails ud) {
        return "loginPage";            
    }

希望这能解决它。