How load servlet on index.jsp

前端 未结 4 1557
广开言路
广开言路 2020-12-29 15:27

Is there is any way to call a servlet on index.jsp? My welcome file is index.jsp. I need to populate dropdown list values by a servlet when i

4条回答
  •  青春惊慌失措
    2020-12-29 15:56

    Just change the welcome file URL to be the one of the servlet.

    Given this servlet mapping,

    
        indexServlet
        /index
    
    

    just have this welcome file list:

    
        index
    
    

    Don't forget to move the /index.jsp into /WEB-INF folder to prevent it from being accessed directly by endusers guessing its URL (and don't forget to alter the forward call in the index servlet to point to /WEB-INF/index.jsp).

    Or if you solely intend to have a "home page servlet" and not an "index servlet", then map the servlet to the empty string URL pattern instead of as welcome file.

    
        indexServlet
        
    
    

    See also:

    • How to call a servlet on jsp page load?
    • Difference between / and /* in servlet mapping url pattern

提交回复
热议问题