zoukankan      html  css  js  c++  java
  • Configure a welcome page in Struts

    Every website need a welcome or default page as an entry point. Here’s 3 ways to configure a welcome page in Struts.

    1. index.jsp

    The simplest way is create a “index.jsp” page and put it same level with the WEB-INF folder, project root folder.

    Access the project root

    http://localhost:8080/StrutsExample/
    

    It will default to index.jsp internally.

    http://localhost:8080/StrutsExample/index.jsp
    

    2. web.xml welcome file

    Declare a welcome-file in web.xml file.

      <welcome-file-list>
    	<welcome-file>
    		/pages/Welcome.jsp
    	</welcome-file>
      </welcome-file-list>
    

    Access the project root

    http://localhost:8080/StrutsExample/
    

    It will redirect to welcome.jsp file internally.

    http://localhost:8080/StrutsExample/pages/Welcome.jsp
    

    web.xml

    <!DOCTYPE web-app PUBLIC
     "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     "http://java.sun.com/dtd/web-app_2_3.dtd" >
    
    <web-app>
      <display-name>Maven Struts Examples</display-name>
      
      <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>
            org.apache.struts.action.ActionServlet
        </servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>
             /WEB-INF/struts-config.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
        
      <servlet-mapping>
           <servlet-name>action</servlet-name>
           <url-pattern>*.do</url-pattern>
      </servlet-mapping>
    
      <welcome-file-list>
    	<welcome-file>
    		/pages/Welcome.jsp
    	</welcome-file>
      </welcome-file-list>
      
    </web-app>
    

    3. JSP Forward

    Create a “index.jsp” file as stated in method 1, and define a JSP forward tag to redirect it to another Struts action.

    index.jsp

    Declare a /Welcome web path, with a ForwardAction type to forward it to another JSP file.

    struts-config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
    "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
    
    <struts-config>
    
    	<action-mappings>
    		
    		<action
    			path="/Welcome"
    			type="org.apache.struts.actions.ForwardAction"
    			parameter="/pages/Welcome.jsp"/>
    		
    	</action-mappings>
    
    </struts-config>
    
  • 相关阅读:
    腾讯测试开发岗一面二面上机编程题
    软件测试工程师职业发展漫谈
    学习 Python,这 22 个包怎能不掌握?
    Loj514「LibreOJ β Round #2」模拟只会猜题意
    后缀数组模板(倍增)
    USACO06DEC 牛奶模式
    BZOJ3680 JSOI2004 平衡点
    loj6278 数列分块入门题2
    loj6277 数列分块入门题1
    Codeforces 383C Propagating tree, 线段树, 黑白染色思想
  • 原文地址:https://www.cnblogs.com/ghgyj/p/4766260.html
Copyright © 2011-2022 走看看