在Servlet请求中获取参数的空值

时间:2017-03-24 21:11:39

标签: java jsp

我有以下JSP

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/custom-functions.tld" prefix="fn"%>

<%@ page import="ca.sait.Constants" session="false"%>

<fmt:setLocale value="${pageContext.request.locale}" />
<fmt:setBundle basename="lang" var="lang" />

<table id="productTable" class="table table-striped table-bordered select"     cellspacing="0" width="100%">
<thead>
    <tr>
        <th>SKU</th>
        <th>Product Name</th>
        <th>Price</th>
        <th></th>
    </tr>
</thead>

<tbody>
<c:forEach items="${model.products}" var="product">
  <tr>
    <td>${product.sku}</td>
    <td>${product.productName}</td>
    <td><fmt:formatNumber type="currency" value="${product.price}" /></td>
    <td width="75px">
        <a onclick="javascript:loadProduct('${product.uuid}');" href="<c:url value="/#products?productId=${product.uuid}" />">View</a>
    </td>
  </tr>
</c:forEach>
</tbody>
</table>

<script type="text/javascript">
   $(document).ready(function() {
        $('#productTable').DataTable();
   } );

function loadProduct(productId) {
    $(".container").load("content/products?productId=" +productId);
}
    </script>

这是我的控制器

@SessionScoped
public class CustomerShoppingController implements IController, Serializable {

/**
 * 
 */
private static final long serialVersionUID = 967656375727676718L;


private final Logger logger = LoggerFactory.getLogger(getClass());

@EJB
private ShoppingCartLocal shoppingCartLocal;

@EJB
private ProductLocal productLocal;


/* (non-Javadoc)
 * @see ca.sait.mvc.controller.IController#process(javax.servlet.http.HttpServletRequest)
 */
@Override
public String process(HttpServletRequest request) {
    logger.trace("ENTER process(request)");

    final String contextPath = request.getServletContext().getContextPath();
    final String resource = request.getRequestURI();
    logger.debug("Resource: {}", resource);

    try {
        final String productId = request.getParameter("productId") ;
        final String qty = request.getParameter("quantity");

        logger.debug("productId: {}", productId);
        logger.debug("quantity: {}", qty);

        final CustomerShoppingCartModel model = new CustomerShoppingCartModel();

        if (!StringUtils.isEmptyOrNull(productId)) {
            try {
                final ShoppingCart shoppingCart = shoppingCartLocal.addProduct(productId, Integer.parseInt(qty));
                model.setCart(shoppingCart);
            } catch(final Exception ex) {
                model.setPageMessage("Invalid Quantity : " + qty);
            }
        }

        request.setAttribute("model", model);

        return "/WEB-INF/jsp/customershoppingcart.jsp";
    } finally {
        logger.trace("EXIT process(request)");
    }
}

当我尝试检索productId和quantity时,我得到空值...我才开始学习Java和JSP(从RPGLE / 400开始)。如果有人能指出我正确的方向,我将不胜感激。它是我的JSP还是控制器/ servlet中缺少的东西?

14:52:11,279 DEBUG [ca.sait.mvc.controller.CustomerShoppingController] (default task-5) Resource: /storefront-web/content/cart
14:52:11,279 DEBUG [ca.sait.mvc.controller.CustomerShoppingController] (default task-5) productId: null
14:52:11,279 DEBUG [ca.sait.mvc.controller.CustomerShoppingController] (default task-5) quantity: null

非常感谢你!

0 个答案:

没有答案