Я хочу использовать один сервлет для многих страниц.Когда я пытаюсь запустить проект, возникает ошибка, потому что запрос заполнен.перепробовал много вариантов шаблонов URL, но сейчас ничего не выходит
, я вижу только один способ.использовать только методы записи и иметь пустой шаблон URL, но я не уверен, что это правильный выбор: D
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>Archetype Created Web Application</display-name>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<filter>
<filter-name>InitialFilter</filter-name>
<filter-class>eshop.filter.InitialFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter>
<filter-name>SessionFilter</filter-name>
<filter-class>eshop.filter.SessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>InitialFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>SessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>mainServlet</servlet-name>
<servlet-class>eshop.controller.MainServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mainServlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<error-page>
<location>/WEB-INF/views/error.jsp</location>
</error-page>
</web-app>
public class IndexCommand implements Command {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, MessagingException, ServiceException, SQLException {
if (request.getSession().getAttribute("role")=="admin")
{
Command command=new AccountCommand();
command.execute(request,response);
}
System.out.println(request.getRequestURI());
request.getRequestDispatcher("/WEB-INF/views/startPage.jsp").forward(request,response);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Command command = CommandFactory.createCommand(request);
try {
command.execute(request, response);
} catch (MessagingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
}
Type Exception Report
Message Servlet execution threw an exception
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
eshop.command.IndexCommand.execute(IndexCommand.java:34)
eshop.controller.MainServlet.doGet(MainServlet.java:62)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
eshop.command.IndexCommand.execute(IndexCommand.java:34)
eshop.controller.MainServlet.doGet(MainServlet.java:62)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.lang.StackOverflowError
eshop.command.IndexCommand.execute(IndexCommand.java:34)
eshop.controller.MainServlet.doGet(MainServlet.java:62)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Как настроить web.xml для сопоставлениясервлет для нескольких шаблонов URL в Java и в чем проблема?