gpt4 book ai didi

java - Spring Mvc学员报名表

转载 作者:行者123 更新时间:2023-11-28 22:49:21 25 4
gpt4 key购买 nike

我是 spring 的新手。我试图编写以下程序的代码,但它给出了 404 错误。我无法跟踪确切的错误位置

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>

描述符网页.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 不存在。

最佳答案

我认为问题在于您的项目没有包含所有库。所以如果您使用的是 Eclipse 和 Maven,请转到

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

关于java - Spring Mvc学员报名表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45605684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com