1
當我提交下面提到的jsp表單時,它不會被提交,也不會在控制檯中顯示任何內容。 瀏覽器顯示錯誤的HTTP 404狀態:客戶端發送的請求在語法上不正確。請求語法錯誤:spring mvc
我的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>
處理該請求的控制器動作/ addTask在AddTaskController
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" ;
}
}
當我提交我的外接任務的形式,它顯示了錯誤: 請求由客戶發送語法不正確
嘗試刪除控制器類中的請求映射,然後嘗試刪除c:url _/addTask_ – kimy82