为什么我的JSF + Spring Web应用程序输出JSF源代码而不是解释HTML页面? [英] Why does my JSF + Spring web application output JSF source code instead of interpreted HTML page?

查看:136
本文介绍了为什么我的JSF + Spring Web应用程序输出JSF源代码而不是解释HTML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JSF和Spring Framework的新手,我正在试图弄清楚如何让它们协同工作。
我当前的问题是应用程序输出我的JSF文件而不解释它们。
以下是我认为可能相关的一些代码片段:

I'm new to both JSF and Spring Framework and I'm trying to figure out how to make them work together. My current problem is that application outputs my JSF files without interpreting them. Here are some snippets of my code which I believe might 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 where the problem might be? Does this code make any sense at all? I'm well aware of fact, that probably completely sucks and I'll be glad to here WHY it sucks and how to make it better. Thanks :)

编辑:我正在添加一段代码,这段代码似乎是问题的根源,而且我(当然)没有包含在原始代码中问题:

I'm adding piece of code which seems to be the root of the problem and which I (of course) didn't 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>

必须将Faces Servlet的url模式更改为* .xhtml才能正常工作。

The url-pattern of Faces Servlet had to be changed to *.xhtml in order to work properly.

推荐答案

如果没有解析JSF标签,那么它只是意味着请求URL与<$ c $不匹配在 web.xml 中定义的 FacesServlet 的c> url-pattern 。它负责所有JSF事件。您需要验证请求URL是否与 FacesServlet url-pattern 匹配。如果它是例如 *。jsf ,那么你需要通过 http://example.com/context/page.jsf 因此不是 http://example.com/context/page.xhtml

If the JSF tags are not been parsed, then it simply means that the request URL did not match the url-pattern of the FacesServlet as definied in web.xml. It is namely responsible for all that JSF happenings. You need to verify if the request URL matches the url-pattern of the FacesServlet. If it is for example *.jsf, then you need to invoke it by http://example.com/context/page.jsf and thus not by http://example.com/context/page.xhtml.

但是我不确定Spring是如何适应图片的,因为我不使用它,但为了让JSF工作,你真的需要首先通过 FacesServlet 传递请求,而不是通过一些Spring控制器。 Spring应该在之后完成它的工作。

I am however not sure how Spring fits in the picture since I don't use it, but to get JSF to work you really need to pass the request through the FacesServlet first, not through some Spring controller. Spring should do its job thereafter.

这篇关于为什么我的JSF + Spring Web应用程序输出JSF源代码而不是解释HTML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆