看到好多网站刚打开时就是 index.do ,请问怎么实现的?还有用户登录时 login.do 之类的,能否给个例子瞧瞧呢?
谢谢啦!
谢谢啦!
解决方案 »
- request.getParameterMap 乱码问题
- 请问一下其中this指代的是谁
- Java webservice实现文件上传
- 一个错误,大家帮忙看看是什么原因
- Action 中如何mapping 到另一个页面或Action???? [ 续... ]
- 关于session的疑问
- 很奇怪的问题,解析XML的时候……
- JSP 下拉列表的问题
- 求救:这个问题我都问了好几次了,希望知道的大侠帮帮忙,使用resin,怎么配置JDBC环境变量?
- 哪里有sqlserver7.0的jdbc驱动啊,兄弟我找了半天没找到,还得请大哥帮忙
- 如何对WebServices进行非对称加密,Java端加密,net端解密?
- 一个关于useBean使用的问题
如果你要用strust2框架的话,在配置文件中配置一下就ok了
"-//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>
- <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中定义
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern> // 这里
</servlet-mapping>
这里就是通知服务器为action分配什么样的请求,是给WEB容器看的,我之前贴的跟着问题没关系,和同事聊天结果给看错了~~当然如果你是用别的模型或者框架,在为中心控制器分配请求类型的时候也可以有类似的相关设置
*.do 被JSP的过滤器进行拦截。你知道struts框架嘛?看看它的资料就知道了