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>
    
  • 相关阅读:
    mybatis中 无效的比较: invalid comparison: java.util.Date and java.lang.String
    java中日期的加减,比较,以及与String的互相转换
    Java中文件上传下载 --使用Minio
    Dubbo SPI 源码深入分析
    新建Maven项目 发布服务 注册到zookeeper
    Dubbo SPI 源码分析
    思维方法
    JDK 和 Dubbo SPI 的入门浅析Demo
    Dubbo不用注册中心实现远程调用的简单用法demo
    解决linux系统下tar解压文件报错问题
  • 原文地址:https://www.cnblogs.com/ghgyj/p/4766260.html
Copyright © 2011-2022 走看看