0

I' new to java programming. I used to do .NET. In my new project which is using java, I want to read the database and load some data into the texboxes in my jsp page.

I used to do this using pageload method in .NET development. I can't find a propper way to do this in jsp.

For now I used the below code samples and it did not work as I wanted.

in servelet

@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //processRequest(request, response);

        request.setAttribute("username", "Uditha");
        request.getRequestDispatcher("/WEB-INF/Download.jsp").forward(request, response);
    }

In JSP

<jsp:include page="/PageLoad" />

<a id="btnUserAccount" type="submit" class="btn btn-default">${result}</a>

It would be very helpful is someone can help me do this. Thank you.

jayz
  • 401
  • 1
  • 5
  • 25
  • 1
    So, what URL is displayed in your address bar, what do you expect to happen (and why), and what happens instead? Which URL is the servlet mapped to? – JB Nizet Jul 02 '16 at 11:17
  • http://localhost:8080/Downloader/Downloader.jsp with a blank page. – jayz Jul 02 '16 at 11:26
  • And what does this Downloader.jsp contain? How about the answers to the other questions? – JB Nizet Jul 02 '16 at 11:30
  • Anyway, you need to learn about MVC. It's quite simple: you go to a URL. This URL is not the URL of a JSP. It's the URL of a servlet, which is the controller. The servlet gets data from the database (the model), stores them in request attributes, and forward to a JSP (the view). The JSP then simply generates HTML displaying the attributes stored by the servlet. As simple as that. – JB Nizet Jul 02 '16 at 11:33

0 Answers0