当我提交下面提到的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>
处理请求的控制器操作是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" ;
}
}
当我提交添加任务表单时,它显示错误: 客户端发送的请求在语法上是不正确的
答案 0 :(得分:0)
尝试以下更改
<body>
<div class="generic-container">
<c:url var="addTask" value="/addTask"/>
<div class="well lead">Add task</div>
<form class="form-horizontal" action="${addTask}">