简体   繁体   English

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

[英]HTTP Status 405 - Request method 'GET' not supported

I want to add payments to my clients database but when I add the payments I got this error "GET NOT SUPPORTED" I don't know what's the problem. 我想向我的客户数据库添加付款,但是当我添加付款时,我收到此错误“GET NOT SUPPORTED”我不知道是什么问题。 Can you guys help me? 你们能帮助我吗?

@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 : 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>

You only seem to have one handler mapping, and it's POST. 您似乎只有一个处理程序映射,它是POST。 Add another handler mapping for the same url path with GET. 使用GET为同一个url路径添加另一个处理程序映射。 Consider the "POST Redirect GET" pattern as well. 考虑“POST Redirect GET”模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM