У меня проблема с отображением моего сервлета на страницу Java Server, с использованием инфраструктуры JSF и особенно тега commandLink.
Когда я нажимаю на команду link, она перезагружает только тот же productList.jsp.
Вот моя карта web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Epimarket</display-name>
<servlet>
<servlet-name>mainServlet</servlet-name>
<servlet-class>com.epimarket.controller.EpimarketServlet</servlet-class>
<init-param>
<param-name>listURL</param-name>
<param-value>productList.jsp</param-value>
</init-param>
<init-param>
<param-name>editURL</param-name>
<param-value>productEdit.jsp</param-value>
</init-param>
<init-param>
<param-name>errorsURL</param-name>
<param-value>errors.jsp</param-value>
</init-param>
</servlet>
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>maxFileSize</param-name>
<param-value>20m</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<servlet-mapping>
<servlet-name>mainServlet</servlet-name>
<url-pattern>/do/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Вот лица лиц-config.xml
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<application>
<locale-config>
<default-locale>fr</default-locale>
</locale-config>
</application>
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>productList</from-outcome>
<to-view-id>/productList.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>productEdit</from-outcome>
<to-view-id>/productEdit.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>chart</from-outcome>
<to-view-id>/chart.jsp</to-view-id>
</navigation-case>
</navigation-rule>
Вот моя ссылка для создания нового продукта (доступ на страницу editProduct.jsp)
<h:commandLink id="createProductLink" value="Ajouter un produit" action="/do/edit"/>
Префикс h предназначен для
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
И, наконец, мои методы doGet и doEditProduct в моем сервлете:
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
if (initErrors.size() != 0)
{
req.setAttribute("erreurs", initErrors);
getServletContext().getRequestDispatcher(urlErrors).forward(req, res);
return ;
}
String reqType = req.getMethod().toLowerCase();
String action = req.getPathInfo();
if (action == null)
action = "/list";
if (reqType.equals("get") && action.equals("/list"))
{
doProductList(req, res);
return ;
}
if (reqType.equals("get") && action.equals("/delete"))
{
doDeleteProduct(req, res);
return ;
}
if (reqType.equals("get") && action.equals("/edit"))
{
doEditProduct(req, res);
return ;
}
if (reqType.equals("post") && action.equals("/validate"))
{
doValidateProduct(req, res);
return ;
}
doProductList(req, res);
}
private void doEditProduct(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
int id = Integer.parseInt(req.getParameter("id"));
Product product = null;
if (id != -1)
product = service.getProduct(id);
else
{
product = new Product();
product.setId(new BigDecimal(-1));
}
req.setAttribute("editError", "");
req.setAttribute("id", product.getId());
req.setAttribute("name", product.getName());
req.setAttribute("description", product.getDescription());
req.setAttribute("price", product.getPrice());
getServletContext().getRequestDispatcher((String)params.get("editURL")).forward(req, res);
}
Спасибо за вашу помощь