0

I have moved from programming in php to jsp for my company and I immediately started with scriptlets. Now I've learned that that's not best practice and that servlets are preferred (and i see why!). However, I'm having trouble finding decent resources to help me get started. What I'm mostly doing is creating an intranet with lots of forms for doing various tasks. So I'm wanting to preprocess some information and then send it to a jsp form then process the changes on submit. I've looked here for some help: How to avoid Java Code in JSP

So I have this in my doGet (which Im not sending any GET variables)

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ArrayList<String> products = new ArrayList();
    products.add("442");
    products.add("TEST");
    request.setAttribute("products", products);
    request.getRequestDispatcher("/inv2.jsp").forward(request, response);
}

and then in my JSP

<div class="content">
    <c:forEach items="${products}" var="product">
        <p>${product}</p>
    </c:forEach>
</div>

But when my servlet forwards to that jsp page the whole page is just blank. I have other code there so if it loaded the page correctly I'd at least see my nav and all that. I don't know what I'm doing or what the best practice is for servlets and most tutorials I'm finding online aren't super helpful. Am I supposed to link to the JSP or the Servlet?

Community
  • 1
  • 1
Andrew
  • 175
  • 1
  • 2
  • 12

0 Answers0