Java 404在这个spring表单项目中单击submit按钮时出错
下面是我的页面,请帮忙 home.jsp searchbus.jspJava 404在这个spring表单项目中单击submit按钮时出错,java,forms,spring,jakarta-ee,spring-mvc,Java,Forms,Spring,Jakarta Ee,Spring Mvc,下面是我的页面,请帮忙 home.jsp searchbus.jsp 请帮我解决这个问题,我根本无法解决问题。您的应用程序是否在web服务器上的应用程序上下文下运行 试试这个: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <form action="<c:url value="/search" />" method="get" name="searchBus"> 表单的动
请帮我解决这个问题,我根本无法解决问题。您的应用程序是否在web服务器上的应用程序上下文下运行 试试这个:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<form action="<c:url value="/search" />" method="get" name="searchBus">
表单的动作sayaction=“search”:
<form action="search" method="get" name="searchBus">
但是,在web.xml中,spring的映射是*。请执行以下操作:
<servlet-mapping>
<servlet-name>TicketStore</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
票务商店
*.做
通过action=“search.do”更改action=“search”
或通过更改映射(不推荐)
票务商店
*
您的控制器中没有HTTP POST的/搜索功能,只有HTTP GET甚至尝试过将其放入。我将所有http请求从get更改为post…但我仍然收到与我尝试时相同的错误。。但是它仍然是一样的。我想在获取searchDetails.java时会遇到一些问题
package com.ticketgoose.controller;
import com.ticketgoose.form.SearchForm;
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.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
@Controller
@SessionAttributes
public class SearchDetails {
@RequestMapping (value = "/search", method = RequestMethod.GET)
public String addContact(@ModelAttribute("searchDetails")
SearchForm searchDetails, BindingResult result){
System.out.println("From:" + searchDetails.getFrom() +
" To:" + searchDetails.getDestination());
return "redirect:searchBus.html";
}
@RequestMapping("/searchBus")
public ModelAndView showContacts() {
return new ModelAndView("searchDetails", "command", new SearchForm());
}
}
<%@ 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>
<title>Success Page</title>
</head>
<body>
User Details
<hr>
From : ${user.name}
To : ${user.gender}
Date of jourey: ${user.country}
Return journey: ${user.aboutYou}
</body>
</html>
package com.ticketgoose.form;
import java.sql.Date;
public class SearchForm {
String from;
String destination;
Date departureDate;
Date returnDate;
//getter setters
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getDestination() {
return destination;
}
public void getDestination(String Destination) {
this.destination = Destination;
}
public Date getDepartureDate() {
return departureDate;
}
public void setDepartureDate(Date departureDate) {
this.departureDate = departureDate;
}
public Date getReturnDate() {
return returnDate;
}
public void setReturnDate(Date returnDate) {
this.returnDate = returnDate;
}}
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<form action="<c:url value="/search" />" method="get" name="searchBus">
<form action="search" method="get" name="searchBus">
<servlet-mapping>
<servlet-name>TicketStore</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>TicketStore</servlet-name>
<url-pattern>*</url-pattern>
</servlet-mapping>