运用Struts1框架来简单实现登陆跳转

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wo3002807/article/details/11831893

功能:运用struts1框架来实现登陆等相关的页面的跳转。

具体的代码在:https://code.csdn.net/dashboard/snippets
步骤:
1,配置web.xml

 <servlet>
      <servlet-name>struts</struts>
      <!--下面是总控制类,要写全路径-->
      <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
       <!--下面是加载struts-config文件-->
      <init-param>
           <param-name>config</param-name>
           <param-value>struts-config.xml的全路径</param-value>
      </init-param>
 </servlet>
 <servlet-mapping>
       <servlet-name>struts</servlet-name>
      <url-pattern>*.do</url-pattern>
 </servlet-mapping>

2,创建log.jsp,success.jsp

忽略.....

3,创建FORM,ACTION类

Form类要继承ActionForm类才行。
 Action要继承Action类,并且要覆写下面这个方法
 public ActionForward execute(ActionMapping mapping, ActionForm form,
  HttpServletRequest request,HttpServletResponse reponse)

 4,配置struts.xml
      <struts-config>
         <form-beans>
              <form-bean name="FormName" type="自己创建继承ActionForm的类的类全名"/>
         </form-beans>
          <action-mappings>
                   <action name="FormName" path="其login.jsp中form标签中{action="names.do"}中的值去掉{.do}" type="自己创建继承Action的类的类全名">
                 <forward name="接收ActionForm类中execute返回的值" path="要跳转到哪个页面"></forward>
                 </action>
           </action-mappings>
 </struts-config>

猜你喜欢

转载自blog.csdn.net/wo3002807/article/details/11831893