2017-08-10 64 views
0

我是初学者的春天。我试图编写下面的程序,但它给404错误。我无法跟踪其确切的错误是春季Mvc学生报名表

throwing HTTP Status 404 - /submitAdmissionForm.html. 
HTTP Status 404 - /submitAdmissionForm.html 

类型状态报告

message /submitAdmissionForm.html 

描述所请求的资源不可用。

enter image description here

的Apache Tomcat/8.0.28


我的文件:

欢迎页面 - index.jsp的

<html> 
<body> 
    <h3> STUDENT ADMISSION FORM FOR ENGINEERING COURSES</h3> 

    <form action="/submitAdmissionForm.html" method="post"> 
     Student's Name : <input type="text" name="studentName" /> 
     Student's Hobby :<input type="text" name="studentHobby" /> 
     Student's Mobile :<input type="text" name="studentMobile" /> 
     Student's DOB :<input type="text" name="studentDOB" /> 
     Student's Skills set 
     <select name="studentSkills" > 
     <option value="Java Core">Java Core</option> 
     <option value="Spring Core">Spring Core</option> 
     <option value="Spring MVC">Spring MVC</option> 
     </select> 
     Student's Address : 

      country: <input type="text" name="studentAddress.country"/> 
      city: <input type="text" name="studentAddress.city" /> 
      street: <input type="text" name="studentAddress.street" /> 
      pincode:<input type="text" name="studentAddress.pincode" /> 
     <input type="submit" value="Submit this form by clicking here" /> 
    </form> 

</body> 
</html> 

描述 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_2_5.xsd" id="WebApp_ID" version="2.5"> 
    <display-name>praygod</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>student</servlet-name> 
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
<servlet-name>student</servlet-name> 
<url-pattern>/</url-pattern> 
</servlet-mapping> 

</web-app> 

学生servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans  
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 


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

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


</beans> 

Controller.java

package com.gappu.student; 

import org.springframework.stereotype.Controller; 
import org.springframework.validation.BindingResult; 
import org.springframework.web.bind.annotation.ModelAttribute; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.servlet.ModelAndView; 


@Controller 
public class studentcontroller { 



    @RequestMapping(value="/submitAdmissionForm.html", method = RequestMethod.POST) 
    public ModelAndView submitAdmissionForm() { 



     ModelAndView model1 = new ModelAndView(); 
     model1.setViewName("AdmissionSuccess"); 
     return model1; 
    } 



} 

这里就是我的成功页面

AdmissionSuccess.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> 
    Hello there 
    </body> 
    </html> 

当我尝试运行此程序它给我的错误是404建议URL不存在。

+0

当tomcat启动时,你可以粘贴tomcat的完整日志吗? –

+0

感谢您的回复..日志中没有错误我添加了服务器日志的图片,请您检查。? –

+0

它可能是资源问题。尝试从表单操作和控制器映射中移除'.html'。另外尝试在你的servlet xml中添加''指向你有实际资源的地方 – StanislavL

回答

1

我认为问题是你的项目不包括所有的库。所以如果你使用Eclipse和Maven,请去

项目属性 - >部署程序集 - >添加 - > Java构建路径条目 - > Maven Dependencies。