gpt4 book ai didi

java - 请求语法错误 : spring mvc

转载 作者:太空宇宙 更新时间:2023-11-04 11:16:42 25 4
gpt4 key购买 nike

当我提交下面提到的 jsp 表单时,它没有被提交,也没有在控制台中显示任何内容。浏览器显示 HTTP 404 状态并显示错误:客户端发送的请求在语法上不正确。

我的 JSP 页面是:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add task</title>
<link href="<c:url value='/static/css/bootstrap.css' />" rel="stylesheet">
</link>
<link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
<c:set var="root" value="${pageContext.request.contextPath}"/>
</head>

<body>
<div class="generic-container">

<div class="well lead">Add task</div>
<form class="form-horizontal" action='<c:url value="addTask"/>'>
<input type="hidden" name="id" id="id"/>

<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable"
for="taskDescription">Task name</label>
<div class="col-md-7">
<input type="text" name="task" id="task" class="form-
control input-sm"/>
<div class="has-error">
</div>
</div>
</div>
</div>

<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable"
for="taskDescription">Task Description</label>
<div class="col-md-7">
<input type="text" name="taskDescription"
id="taskDescription" class="form-control input-sm" />
<div class="has-error">
</div>
</div>
</div>
</div>


<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="fromTime">From
Time</label>
<div class="col-md-7">
<input type="text" name="fromTime" id="fromTime"
class="form-control input-sm" />
<div class="has-error">
</div>
</div>
</div>
</div>

<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="toTime">To
Time</label>
<div class="col-md-7">
<input type="text" name="toTime" id="toTime"
class="form-control input-sm" />
<div class="has-error">
</div>
</div>
</div>
</div>



<div class="row">
<div class="form-actions floatRight">
<input type="submit" value="Add" class="btn btn-
primary btn-sm"/>
</div>
</div>
</form>
</div>
</body>
</html>

处理请求的 Controller Action 是AddTaskController中的/addTask

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.websystique.springmvc.model.AddTask;
import com.websystique.springmvc.service.TaskService;

@Controller
@RequestMapping("/")
public class AddTaskController {

private TaskService taskService;

@RequestMapping("/task")
String task(){
System.out.println("Inside task action");
return "addTask/addTask";
}

@RequestMapping("/addTask")
String addTask(@ModelAttribute AddTask a){
System.out.println("Inside addTask action");
this.taskService.addTask(a);
return "redirect:/task" ;
}

}

当我提交添加任务表单时,它显示错误:客户端发送的请求在语法上不正确

最佳答案

尝试以下更改

<body> 
<div class="generic-container">

<c:url var="addTask" value="/addTask"/>

<div class="well lead">Add task</div>
<form class="form-horizontal" action="${addTask}">

关于java - 请求语法错误 : spring mvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45396914/

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