Danil.B
Danil.B

Reputation: 900

Long URL in Spring MVC application

I'm creating a Spring MVC application using a lot of form inputs and model attributes with multiple List fields.On my jsp page I have something like catalog in which user can specify which product of different size he want's to order. index.jsp:

    <div class="catalog_element">
                    <img src="/resources/img/fb.png" width="250px" height="250px" class="product_image"/>
                    <h4>Фундаментные блоки</h4>
                    <div class="product_picker">
                        <div class="show_fb_content">
                            <img width="80px" height="40px" src="/resources/img/pointer_down.png">
                        </div>
                        <div class="fb_content">
                            <div class="product_item">
                                <h3>Размер L H B </h3>
                                <h3 class="amount_input">Кол</h3>
                            </div>
                            <c:forEach items="${FBContainer.products}" varStatus="i" var="product">
                                <div class="product_item">
                                    <h3>${product.toString()}</h3>
                                    <form:input cssClass="amount_input"
                                                path="fbContainer.products[${i.index}].amount"/>
                                </div>
                            </c:forEach>
                        </div>
                    </div>
                </div>
 <div class="catalog_element">
                    <img src="/resources/img/roadplates.png" width="250px" height="250px" class="product_image"/>
                    <h4>Плиты перекрытия</h4>
                    <div class="product_picker">
                        <div class="show_fb_content">
                            <img width="80px" height="40px" src="/resources/img/pointer_down.png">
                        </div>
                        <div class="fb_content">
                            <div class="product_item">
                                <h3>Размер L H B </h3>
                                <h3 class="amount_input">Кол</h3>
                            </div>
                            <c:forEach items="${CPContainer.products}" varStatus="i" var="product">
                                <div class="product_item">
                                    <h3>${product.toString()}</h3>
                                    <form:input cssClass="amount_input"
                                                path="cpContainer.products[${i.index}].amount"/>
                                </div>
                            </c:forEach>
                        </div>
                    </div>
                </div>

So, in forEach loop I create an input for amount for every kind of product. And every product type(there is 6 of them) has its own container. Something like CPContainer:

public class CPContainer implements Container {

    private List<CPProduct> products;
    private int id;
    private int amount;

    @Override
    public List<CPProduct> getProducts() {
        return products;
    }

    @Override
    public CPProduct getProductById(int id) {
        return products.get(id);
    }

    public void setProducts(List<CPProduct> products) {
        this.products = products;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    @Override
    public String toString() {
        return "CPContainer{" +
                "products=" + products +
                ", id=" + id +
                ", amount=" + amount +
                '}';
    }
}

Not sure if that's a problem but when I fill the form, on order's page I see a very long URL,with many parameters : http://localhost:8080/calculate?fbContainer.products%5B0%5D.amount=3&fbContainer.products%5B1%5D.amount=2&fbContainer.products%5B2%5D.amount=0&cpContainer.products%5B0%5D.amount=0&cpContainer.products%5B1%5D.amount=0&cpContainer.products%5B2%5D.amount=0&jumperContainer.products%5B0%5D.amount=0&jumperContainer.products%5B1%5D.amount=0&jumperContainer.products%5B2%5D.amount=0&vbContainer.products%5B0%5D.amount=0&vbContainer.products%5B1%5D.amount=0&vbContainer.products%5B2%5D.amount=0&bbContainer.products%5B0%5D.amount=0&bbContainer.products%5B1%5D.amount=0&bbContainer.products%5B2%5D.amount=0&pbContainer.products%5B0%5D.amount=0&pbContainer.products%5B1%5D.amount=0&pbContainer.products%5B2%5D.amount=0. Is this bad, or should I leave it like that?

Upvotes: 0

Views: 402

Answers (1)

san
san

Reputation: 98

Use POST method in place of GET. GET request generate request parameter which are visible in URL. Like this:

Upvotes: 2

Related Questions