Why does a JSF + Spring web application output JSF source code instead of an interpreted HTML page?

I am new to JSF and Spring Framework, and I'm trying to figure out how to get them to work together. My current problem is that the application outputs my JSF files without interpreting them. Here are some pieces of my code that, in my opinion, may be relevant:

dispatcher-servlet.xml

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="login.htm">loginController</prop>
        </props>
    </property>
</bean>

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/pages/"
      p:suffix=".xhtml" />

<bean name="loginController" class="controller.LoginController" />

LoginController

public class LoginController extends MultiActionController {
 public ModelAndView login(HttpServletRequest request,
   HttpServletResponse response) throws Exception {
    System.out.println("LOGIN");
    return new ModelAndView("login");
}

WEB-INF / pages / login.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <title>#{message.log}</title>
</h:head>
<h:body>
    <h:form>
        <h:outputLabel value="#{message.username}" for="userName">
            <h:inputText id="userName" value="#{User.name}" />
        </h:outputLabel>            
        <h:commandButton value="#{message.loggin}" action="#{User.login}" />
    </h:form>
</h:body>
</html>

Any ideas you might have a problem in? Does this code really make sense? I well know that maybe it sucks completely, and I will be happy here, WHY this sucks and how to make it better. Thank:)

EDIT: I am adding a piece of code that seems to be the root of the problem and which I (of course) did not include in the original question:

web.xml

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<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>dispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

, url- Faces Servlet *.xhtml.

+3
1

JSF , , URL- url-pattern FacesServlet, web.xml. JSF. , URL- url-pattern FacesServlet. , , *.jsf, http://example.com/context/page.jsf , , http://example.com/context/page.xhtml.

, Spring , , JSF , FacesServlet , - Spring . Spring .

+2

Source: https://habr.com/ru/post/1745900/


All Articles