logic:redirect 跳转问题

在自己的网站开发中遇到的一个小问题

目的:运行 index.jsp 页 自动跳转到 home.jsp 主页面。
index.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="/tld/struts-logic" prefix="logic" %>
<logic:redirect forward="home"/>

struts-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
         
<struts-config>

<!-- form -->
<form-beans>
<form-bean name="loginForm" type="com.zero.front.login.action.LoginForm"></form-bean>
</form-beans>


<global-forwards>
        <forward name="home" path="/home.do"/>
    </global-forwards>
   
    <!-- action -->
<action-mappings>
<action path="/home"  validate="false" name="loginForm" forward="/jsp/login/login.jsp" scope="request">
</action>

<action path="/login" type="com.zero.front.login.action.LoginAction" name="loginForm" scope="request">
<forward name="success" path="/jsp/common/home.jsp"></forward>
</action>
</action-mappings>
</struts-config>

以上是源文件
注意的是
1、<logic:redirect forward="home"/> 中 forward 用的是全局变量<global-forwards>
2、<action path="/home"  validate="false" name="loginForm" forward="/jsp/login/login.jsp" scope="request"> 直接跳转不需要type的action的写法
3、期间遇到过 “Cannot find ActionMappings or ActionFormBeans collection” 错误是由于struts-config.xml没有配置正确,以及 struts.jar包没有引全 共10个包,还有就是可能 web.xml 配置错误。


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>zero</display-name>
	<servlet>
		<!-- Standard Action Servlet Configuration (with debugging) -->
		<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/config/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>
		[color=red]<load-on-startup>0</load-on-startup>[/color]
	</servlet>
	<servlet>
		<servlet-name>nitrox-debugger-tomcat5</servlet-name>
		<servlet-class>
			org.apache.jasper.servlet.JspServlet
		</servlet-class>
		<init-param>
			<param-name>suppressSmap</param-name>
			<param-value>true</param-value>
		</init-param>
		<load-on-startup>3</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>nitrox-debugger-tomcat5</servlet-name>
		<url-pattern>*.jsp</url-pattern>
	</servlet-mapping>
	
	<servlet-mapping>
		<servlet-name>action</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	
	
	<welcome-file-list>
		<welcome-file>index.do</welcome-file>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
	
<!--应用标签 -->
	<jsp-config>
		<taglib>
			<taglib-uri>/tld/struts-bean</taglib-uri>
			<taglib-location>
				/WEB-INF/tld/struts-bean.tld
			</taglib-location>
		</taglib>
		<taglib>
			<taglib-uri>/tld/struts-html</taglib-uri>
			<taglib-location>
				/WEB-INF/tld/struts-html.tld
			</taglib-location>
		</taglib>
		<taglib>
			<taglib-uri>/tld/struts-logic</taglib-uri>
			<taglib-location>
				/WEB-INF/tld/struts-logic.tld
			</taglib-location>
		</taglib>


		<taglib>
			<taglib-uri>/tld/struts-tiles</taglib-uri>
			<taglib-location>
				/WEB-INF/tld/struts-tiles.tld
			</taglib-location>
		</taglib>

		<taglib>
			<taglib-uri>/tld/struts-nested</taglib-uri>
			<taglib-location>
				/WEB-INF/tld/struts-nested.tld
			</taglib-location>
		</taglib>
	</jsp-config>
</web-app>

你可能感兴趣的:(apache,jsp,Web,xml,struts)