Как URL-адрес работает в Spring Web-потоке?

Ниже приведен адрес моего проекта. http://localhost:8080/springwebflow/loginFlow;jsessionid=k7338gzuvyc2sk36axkzhe9r?execution=e1s1

Как работает путь springwebflow/loginFlow? и с этим путем как мой display_login.jsp приходит?

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app
<?xml version="1.0" encoding="UTF-8" ?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="com.studytrails.tutorials.springwebflow" />

    <!--Define FlowHandlerMapping to tell DispatcherServlet (in web.xml)
          to send flow requests to Spring Web Flow -->
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
        <property name="flowRegistry" ref="loginFlowRegistry" />
    </bean>

    <!-- Define FlowHandlerAdapter to handle Spring Web Flow request call.
            This is the Controller class in Spring Web Flow -->
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
        <property name="flowExecutor" ref="loginFlowExecutor" />
    </bean>

</beans>
3.dtd" > <web-app> <display-name>Spring Web Flow</display-name> <servlet> <servlet-name>login</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/config/login-servlet-config.xml /WEB-INF/config/login-webflow-config.xml /WEB-INF/config/spring-config.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>login</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>

веб.xml

<?xml version="1.0" encoding="UTF-8" ?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="com.studytrails.tutorials.springwebflow" />

    <!--Define FlowHandlerMapping to tell DispatcherServlet (in web.xml)
          to send flow requests to Spring Web Flow -->
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
        <property name="flowRegistry" ref="loginFlowRegistry" />
    </bean>

    <!-- Define FlowHandlerAdapter to handle Spring Web Flow request call.
            This is the Controller class in Spring Web Flow -->
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
        <property name="flowExecutor" ref="loginFlowExecutor" />
    </bean>

</beans>

логин-servlet-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:flow="http://www.springframework.org/schema/webflow-config"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow-config
                        http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
                        http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

        <!-- Define the flow executor responsible for executing login web flow -->              
        <flow:flow-executor id="loginFlowExecutor" flow-registry="loginFlowRegistry"/>

        <!-- Define the registry that holds references to all the flow related XML configuration-->
        <flow:flow-registry id="loginFlowRegistry">
            <flow:flow-location id="loginFlow" path="/WEB-INF/flows/login-flow.xml"/>
        </flow:flow-registry>       

</beans>

логин-webflow-config.xml

<%@ page isELIgnored ="false" %>

<html xmlns:form="http://www.springframework.org/tags/form">

    <body>
        <form action="${flowExecutionUrl}&_eventId=loginCredentialsEntered" method="post"> 

            <input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
            <br/>
            Enter login name as <b>alba</b> and password as <b>pass</b> for successfull login.
            <br/>
            Use any other login name and password for login error.
            <br/>
            <br/>
            <table>
                <tr>
                    <td>Login Name:</td>
                    <td><input type="text" name="loginName"/></td>
                </tr>
                <tr>
                    <td>Password: </td>
                    <td><input type="text" name="password"/></td>
                </tr>
            </table>

            <br/>           
            <input type="submit" value="Login" />

        </form>
    </body>
</html>

display_login.jsp

PFA — это мои файлы, не могли бы вы объяснить, как потоки работают с URL-адресами.


person Sandeep Choudhari    schedule 25.11.2015    source источник


Ответы (2)


Итак, если я понял ваш вопрос, вы хотите отобразить свой jsp, используя поток. Обычно мы используем такую ​​иерархию:

vue
-src/main/java
-controllers
-src/main/resources
-Meta-INF
-flows
-page-folder
-page-flow .xml
-resources
-page-folder
-page.xhtml

В каждой папке есть один файл .xml, вы можете добавить вложенную папку, а затем поместить в нее свой xml. Для вашего потока это должно быть так:

  <?xml version="1.0" encoding="UTF-8"?>
  <flow xmlns="http://www.springframework.org/schema/webflow"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/webflow
    http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
parent="default">

<view-state id="myPage" view="/page-folder/page.xhtml">
    <on-entry>
        <evaluate expression="pageController.init()"></evaluate>
    </on-entry>
    <transition on="cancel" to="close"/> 
   </view-state>

   </flow>

если вы хотите узнать, как представления отображаются с помощью весеннего потока: https://spring.io/blog/2007/11/15/the-spring-web-flow-2-0-vision

Лучше посмотреть в официальной документации.

person K.Mouna    schedule 25.11.2015
comment
Привет, спасибо за ваш ответ. мой вопрос: когда я нажимаю на localhost: 8080/springwebflow/loginFlow, как появляется мой display_login.jsp? - person Sandeep Choudhari; 26.11.2015

Во-первых, вы можете добавить подстановочный шаблон для указания (шаблон местоположения потока), который создаст правило о том, как регистрировать потоки. Это позволит вам зарегистрировать множество потоков с помощью 1 правила вместо жесткого кодирования каждого из них вручную. (Примечание: ниже приведен неофициальный «стандартный и лучший способ» регистрации потоков)

<!-- The registry of executable flow definitions --> 
    <webflow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows" flow-builder-services="flowBuilderServices">
        <webflow:flow-location-pattern value="/**/*-flow.xml" />
    </webflow:flow-registry>

Таким образом, приведенное выше правило гласит:

  1. Запустите сканирование в каталоге «/WEB-INF/flows» (убедитесь, что он существует)
  2. Для любых подкаталогов найдите любые файлы с суффиксом «-flow.xml».
  3. Для каждого совпадения зарегистрируйте этот поток в реестре потоков

После этого вы можете перейти к зарегистрированному потоку по URL-адресу, с которым он сопоставлен, из любого места вашего приложения.

Используя пример потока:

/WEB-INF/flows/path/to/process1/reservation-flow.xml   // note: ends in "-flow.xml"

будет доступен через HTTP-запрос на получение:

http://(my-web-server-ip):(port)/path/to/process1

(примечание: «потоки» НЕ включены в URL-адрес, потому что мы установили его как часть атрибута base-path="/WEB-INF/flows" в определении реестра потоков и обратите внимание, что имя файла потока НЕ ​​используется вообще в запросе только каталог, в котором определен поток)


Дополнительные сведения см. в этом ответе: Расположение потока Webflow по URI?

person Selwyn    schedule 30.11.2015