K
K
Konstantin2017-02-06 12:21:17
Java
Konstantin, 2017-02-06 12:21:17

JAVA EE how to set unique html for dynamic page?

Good afternoon. The bottom line is that there is a list of portfolio works in the database, each work has an alias field. You need to make sure that when you click on the site.com/projects/one_project_alias.html link, the servlet is launched, opens the corresponding jsp file project.jsp and runs the required class. My difficulty is to process the URL correctly (I know how to work with a specific address, but I don’t know how to set a template for several addresses in urlPatterns), I also need to get one_project_alias and pass it as a parameter to the function (I use it from the database get the right page)

@javax.servlet.annotation.WebServlet(name = "PageLogotip", urlPatterns = "/project/как_указать_все_страницы?")
public class PageLogotip extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        try{
            request.setAttribute("posts", DAO.getSiteWorks(alias)); //КАК ПОЛУЧИТЬ ALIAS ИЗ URL?
        } catch (SQLException | ClassNotFoundException e){
            e.printStackTrace();
        }
        request.getRequestDispatcher("WEB-INF/project.jsp").forward(request, response);
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question