2

I am writing a java web application using Servlets. It contains two buttons and each one imports some data from some csv files. When a button is pressed the csv files are loaded in again.

Is there any way to load the csv files when the page is iniated? So I will Objectify the csv files to use them later instead of loading them all the time.

Each button is a servlet and it contains this code:

protected void doGet(HttpServletRequest req,HttpServletResponse resp)
            throws ServletException, IOException
    {
        String code=req.getParameter("code");
        String name= req.getParameter("name");

        CSVReader reader=new CSVReader();
        ArrayList<Person> people=reader.readPeople(); // reading from csv files
        reader.readParents();
        reader.readKids();

1 Answer 1

2
public class OnStart implements ServletContextListener {
    public void contextInitialized(ServletContextEvent event) {
        //Things for the application to do when it starts
    }

}

and in the web.xml file

<listener>
    <listener-class>OnStart</listener-class>
</listener>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.