2017-07-30 103 views
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" ; 
} 

} 

当我提交我的外接任务的形式,它显示了错误: 请求由客户发送语法不正确

+0

尝试删除控制器类中的请求映射,然后尝试删除c:url _/addTask_ – kimy82

回答

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}"> 
+0

中没有人的请求映射..它不以这种方式工作。 –