login page:
<form action="">
<table width="100%" border="0"
<TR valign="bottom">
<TD ALIGN="left" nowrap="nowrap">
<br/>
<input type="hidden" value="login" name="reqCode" id="reqCode" /><br/>
<input type="button" onclick="aaaaa()" value="testSSO"><br/>
</TD>
</TR>
</table>
</form>
</body>
<script language="JavaScript" type="text/JavaScript">
function aaaaa(){
with(document.forms[0]){
action = '<%=request.getContextPath()%>/loginAction.do';
submit();
}
}
</script>
</html>
login action:
package com;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
public class LoginAction extends DispatchAction{
public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
System.out.println("bbbbbbbbbbbbbbbbb1");
return new ActionForward("/web/success.jsp");
}
}
web.xml
<?xml version="1.0" encoding="utf-8"?>
<!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>
<context-param>
<param-name>struts-layout-config</param-name>
<param-value>config</param-value>
</context-param>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com.IQActionServlet</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>
<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>
</web-app>
IQActionServlet
package com;
import java.io.IOException;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class IQActionServlet extends ActionServlet {
public void init() throws ServletException {
System.out.println("Start IQActionServlet");
super.init();
}
struts-config.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
</form-beans>
<action-mappings>
<action path="/loginAction"
type="com.LoginAction"
scope="request"
parameter="reqCode"
validate="false">
<forward name="success"
path="success.jsp" />
</action>
</action-mappings>
</struts-config>
4个jar:
xml: