[英]Why does my JSF + Spring web application output JSF source code instead of interpreted HTML page?
我是JSF和Spring Framework的新手,我正在试图弄清楚如何让它们协同工作。 我目前的问题是应用程序输出我的JSF文件而不解释它们。 以下是我的代码的一些片段,我认为这些片段可能是相关的:
调度员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 /页/ 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>
任何可能出现问题的想法? 这段代码是否有意义? 我很清楚事实,这可能完全糟透了,我会很高兴在这里为什么它糟透了,如何让它变得更好。 谢谢 :)
编辑:我正在添加一段代码,这似乎是问题的根源,我(当然)没有包含在原始问题中:
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>
必须将Faces Servlet的url模式更改为* .xhtml才能正常工作。
如果没有解析JSF标记,那么它只是意味着请求URL与web.xml
中定义的FacesServlet
的url-pattern
不匹配。 它负责所有JSF事件。 您需要验证请求URL是否与FacesServlet
的url-pattern
匹配。 如果它是例如*.jsf
,则需要通过http://example.com/context/page.jsf
调用它,因此不需要通过http://example.com/context/page.xhtml
调用它。
但是我不确定Spring是如何适应图片的,因为我没有使用它,但为了让JSF工作,你真的需要首先通过FacesServlet
传递请求,而不是通过一些Spring控制器。 Spring应该在此之后完成它的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.