看到好多网站刚打开时就是 index.do  ,请问怎么实现的?还有用户登录时 login.do 之类的,能否给个例子瞧瞧呢?
谢谢啦!

解决方案 »

  1.   

    过滤器!
    如果你要用strust2框架的话,在配置文件中配置一下就ok了
      

  2.   

    <?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>
        <form-beans>
            <form-bean name="LogForm" type="com.myapp.icp.formbean.LogForm"/>
            <form-bean name="MessageForm" type="com.myapp.icp.formbean.MessageForm"/>
            <form-bean name="LoginForm" type="com.myapp.icp.formbean.LoginForm"/>
            <form-bean name="RegisterForm" type="com.myapp.icp.formbean.RegisterForm"/>
        </form-beans>
        
        <global-exceptions></global-exceptions>    <global-forwards>
            <forward name="welcome"  path="/Welcome.do"/>
            <forward name="error" path="/html/error.html" />
        </global-forwards>    <action-mappings>
            <action attribute="MessageForm" input="/message.jsp" name="MessageForm" path="/message" scope="session" type="com.myapp.icp.action.MessageAction">
                <forward name="success" path="/jsp/message.jsp"></forward>
                <forward name="failed" path="/failed.jsp"></forward>
            </action>
            <action input="/" name="LogForm" path="/log" scope="session" type="com.myapp.icp.action.LogAction">
                <forward name="success" path="/success.jsp"></forward>
                <forward name="failed" path="/failed.jsp"></forward>
            </action>
            <action input="/jsp/login.jsp" name="LoginForm" path="/login" scope="session" type="com.myapp.icp.action.LoginAction"/>
            <action input="/jsp/register.jsp" name="RegisterForm" path="/register" scope="request" type="com.myapp.icp.action.RegisterAction"/>
            <action path="/validate_code" type="com.myapp.icp.action.ValidationCodeAction" parameter="validate_code" />
            <action path="/Welcome" forward="/welcomeStruts.jsp"/>
        </action-mappings>
        
        <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>    <message-resources parameter="com/myapp/struts/ApplicationResource"/>    
        
        <!-- ========================= Tiles plugin ===============================-->
        <!--
        This plugin initialize Tiles definition factory. This later can takes some
        parameters explained here after. The plugin first read parameters from
        web.xml, thenoverload them with parameters defined here. All parameters
        are optional.
        The plugin should be declared in each struts-config file.
        - definitions-config: (optional)
        Specify configuration file names. There can be several comma
        separated file names (default: ?? )
        - moduleAware: (optional - struts1.1)
        Specify if the Tiles definition factory is module aware. If true
        (default), there will be one factory for each Struts module.
        If false, there will be one common factory for all module. In this
        later case, it is still needed to declare one plugin per module.
        The factory will be initialized with parameters found in the first
        initialized plugin (generally the one associated with the default
        module).
        true : One factory per module. (default)
        false : one single shared factory for all modules
        - definitions-parser-validate: (optional)
        Specify if xml parser should validate the Tiles configuration file.
        true : validate. DTD should be specified in file header (default)
        false : no validation    Paths found in Tiles definitions are relative to the main context.
        -->
        <plug-in className="org.apache.struts.tiles.TilesPlugin" >
            <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />      
            <set-property property="moduleAware" value="true" />
        </plug-in>
        
        <!-- ========================= Validator plugin ================================= -->
        <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
            <set-property property="stopOnFirstError" value="false" />
        </plug-in>
      
    </struts-config>
      

  3.   

    <?xml version="1.0" encoding="UTF-8" ?> 
    - <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    - <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>
    - <init-param>
      <param-name>debug</param-name> 
      <param-value>2</param-value> 
      </init-param>
    - <init-param>
      <param-name>detail</param-name> 
      <param-value>2</param-value> 
      </init-param>
      <load-on-startup>2</load-on-startup> 
      </servlet>
    - <servlet-mapping>
      <servlet-name>action</servlet-name> 
      <url-pattern>*.do</url-pattern> //  这里
      </servlet-mapping>
    - <session-config>
      <session-timeout>30</session-timeout> 
      </session-config>
    - <welcome-file-list>
      <welcome-file>index.jsp</welcome-file> 
      </welcome-file-list>
    - <jsp-config>
    - <taglib>
      <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> 
      <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> 
      </taglib>
    - <taglib>
      <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> 
      <taglib-location>/WEB-INF/struts-html.tld</taglib-location> 
      </taglib>
    - <taglib>
      <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri> 
      <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> 
      </taglib>
    - <taglib>
      <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri> 
      <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> 
      </taglib>
    - <taglib>
      <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri> 
      <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> 
      </taglib>
      </jsp-config>
      </web-app>不好意思贴错了~~这个是一般要在WEB-INF下的WEB.XML中定义
      

  4.   

    <servlet-mapping>
      <servlet-name>action</servlet-name> 
      <url-pattern>*.do</url-pattern> //  这里
    </servlet-mapping>
    这里就是通知服务器为action分配什么样的请求,是给WEB容器看的,我之前贴的跟着问题没关系,和同事聊天结果给看错了~~当然如果你是用别的模型或者框架,在为中心控制器分配请求类型的时候也可以有类似的相关设置
      

  5.   

    在struts中web.xml中的<url-pattern>*.do</url-pattern>  默认是*.do
      

  6.   


    *.do 被JSP的过滤器进行拦截。你知道struts框架嘛?看看它的资料就知道了
      

  7.   

    晕了,推荐看看张孝祥最新的struts1的高级进阶课程。
      

  8.   

    struts1中默认的是.do struts2中有好多中写法,struts1中也可以有多种写法不一定是.do
      

  9.   

    这个不是struts默认的吗,我都不明白你什么意思,学一下strsuts应该就能了解!
      

  10.   

    恩,struts默认的就是这个样子
      

  11.   

    自己加上去的,你自己也可以在mapping里面这么写
      

  12.   

    *.do不是文件,是一个URL,WEB服务器据此决定由哪个servlet去处理
      

  13.   

    这个随便你改的,在 Struts 1.x 中一般在 web.xml 中配置成 *.do,因为 Struts 1.x 是由一个核心控制器管理的,这个控制器就是一个 Servlet。我们可以改成 *.bank 也可以,让别人看着更神秘。
      

  14.   

    可以使用过滤器,我前两天做了个2周内自动登录的功能,和你说这种情况一样,把相关代码以及封成了jar包,通过访问http://127.0.0.1:8989/oa 即可以直接显示登录后的页面,如果你需要加我QQ:478874237,我可以把那个包提供给你。