0

I would like to call a servlet GetUserData on load of aboutme.jsp page.

Basically what it does is setting up a session variables that allows user to see his profile info.

It sets a session variable so it doesn't need to invoke anything just proceed with the servlet on page load.

@WebServlet("/GetUserData")
public class GetUserData extends HttpServlet {
 
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        HttpSession session = request.getSession(); 
        String login=(String)session.getAttribute("login"); 
        Profile profile = new Profile();
        Object[] userData = profile.getData(login);
        session.setAttribute("name",userData[0]);  
        session.setAttribute("surname",userData[1]); 
        session.setAttribute("password",userData[3]);
        session.setAttribute("address",userData[4]);
        session.setAttribute("acc_type",userData[5]);
        session.setAttribute("org",userData[6]);
        RequestDispatcher rs = request.getRequestDispatcher("aboutme.jsp");
        rs.include(request, response);
    }  
}

This servlet calls out another method to make SQL statements and prepare data to be send through.

Lastly on a JSP page I would like to print into the table all the information (like login, password, etc) using previously declared session variables.

How can I invoke this servlet so it will run on page load?

I tried already request dispatcher with forward option and the

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

option but Eclipse returns an eror because of mistaken path.

Here's my files structure. file structure

And as for the final result, I was going to do something like this:

<tr>
    <td>Name</td>
    <td><input class="form-control" id="disabledInput" type="text" name="name" value="<% out.println((String)session.getAttribute("name")); %>" readonly></td>
</tr>

Any help appreciated.

janki3l
  • 39
  • 5

0 Answers0