HTTP状态405 - 请求方法' GET'不支持

时间:2015-02-21 16:55:35

标签: java spring hibernate jsp spring-mvc

我想向我的客户数据库添加付款,但是当我添加付款时,我收到此错误“GET NOT SUPPORTED”我不知道问题是什么。你们能帮助我吗?

@Controller
public class PaymentsController {

    @Autowired
    private UsersService usersService;
    @Autowired
    private PaymentsService paymentsService;

    @RequestMapping(value = "/addPayments", method = RequestMethod.POST)
    public String addPayments(HttpServletRequest request, ModelMap map) {
        String user = request.getParameter("userId"); // this is the identifier for the user of this payment
        String transactName = request.getParameter("transactName");
        String paid = request.getParameter("paid");
        String unpaid = request.getParameter("unpaid");
        String balance = request.getParameter("balance");
        String total = request.getParameter("total");
        //.... get all other attributes you've passed from the form through request.getParameter("");

        //next, check whether or not a user with the userId from the screen exists in the db
        Users userObject = usersService.getUsers(user);
        //.getUsersByUserId(user);
        if (userObject != null) {
            // this means that we have a valid user to insert the payment to
            UsersPayments payment = new UsersPayments();
            payment.setUsers(userObject);
            payment.setTransactName(transactName);
            payment.setPaid(paid);
            payment.setUnpaid(unpaid);
            payment.setBalance(balance);
            payment.setTotal(total);
            //....  set the other properties of UsersPayment object

            paymentsService.addPayments(payment);
        }
        else {
            // you have an error right here
        }
        map.put("paymentsList", paymentsService.getAllPayments());
        return "payments";
    }
}

payments.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ include file="/WEB-INF/jsp/includes.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="<c:url value="/resources/css/design.css" />" rel="stylesheet">
<link href="<c:url value="/resources/css/customized.css" />" rel="stylesheet">
<link href="<c:url value="/resources/css/bootstrap.css" />" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Canadian Immigration Consultancy</title>
</head>
<body>
<div id="wrapper">
    <div id="logo">
        <img src="<c:url value="/resources/images/logo4.png" />" height="200px" width="230px"/>
        <img src="<c:url value="/resources/images/header06.jpg" />" height="200px" width="765px"/>
    </div>  

    <div class="red">
        <div align="center" id="slatenav">
            <ul>
                <li><a href="http://localhost:8080/SoftwareProject/home" title="css menus">Home</a></li>
                <li><a href="http://localhost:8080/SoftwareProject/viewAll" title="css menus">View All</a></li>
                <li><a href="#" title="css menus">Reports</a></li>
                <li><a href="http://localhost:8080/SoftwareProject/addleads">Add Leads</a></li>
                <li><a href="<c:url value='j_spring_security_logout'/>"><spring:message code="user.logout"/></a></li>
            </ul>
        </div>
    </div>

    <div id="balance" >
    <form action="addPayments" method="POST">
       <div class="well well-sm box16">
        <div class="panel panel-info">
            <div class="panel-heading">
                <h3 class="panel-title">Payments</h3>
            </div>
            <div class="panel-body">



    <div class="form-group">
       <br><div  class="col-sm-2 control-label">Transaction Name</div>
        <div class="col-sm-10">
          <input type="text" class="form-control" name="transactName"  autofocus />
        </div>
    </div>


      <div class="form-group">
       <br><div class="col-sm-2 control-label">Amount Paid</div>
        <div class="col-sm-10">
          <input type="text" class="form-control" name="paid" />
        </div>
    </div>


      <div class="form-group">
       <br><div class="col-sm-2 control-label">Unpaid</div>
        <div class="col-sm-10">
          <input type="text" class="form-control" name="unpaid" />
        </div>
    </div>


      <div class="form-group">
       <br><div class="col-sm-2 control-label">Total Balance</div>
        <div class="col-sm-10">
          <input type="text" class="form-control" name="balance" />
        </div>
    </div>


      <div class="form-group">
       <br><div class="col-sm-2 control-label">Total Amount</div>
        <div class="col-sm-10">
          <input type="text" class="form-control" name="total" />
        </div>
    </div>




    <div class="save">

                    <input type="submit" class="btn btn-success" value="Save" />


    </div>
        </form>     
            </div>
        </div>




</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您似乎只有一个处理程序映射,它的POST。使用GET为同一个url路径添加另一个处理程序映射。考虑&#34; POST Redirect GET&#34;模式也是如此。