转自:https://blog.csdn.net/dongzhout/article/details/43699699

搭建好SSH2框架,写一个简单的登陆功能,提交表单的时候遇到这个问题:

配置文件如下:

web.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="3.0"
  3. xmlns="http://java.sun.com/xml/ns/javaee"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  6. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  7. <display-name></display-name>
  8. <context-param>
  9. <param-name>contextConfigLocation</param-name>
  10. <param-value>classpath:applicationContext.xml</param-value>
  11. </context-param>
  12. <listener>
  13. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  14. </listener>
  15. <welcome-file-list>
  16. <welcome-file>index.jsp</welcome-file>
  17. </welcome-file-list>
  18. <filter>
  19. <filter-name>struts2</filter-name>
  20. <filter-class>
  21. org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  22. </filter-class>
  23. <init-param>
  24. <param-name>config</param-name>
  25. <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
  26. </init-param>
  27. </filter>
  28. <filter-mapping>
  29. <filter-name>struts2</filter-name>
  30. <url-pattern>*.action</url-pattern>
  31. </filter-mapping>
  32. <filter-mapping>
  33. <filter-name>struts2</filter-name>
  34. <url-pattern>*.jsp</url-pattern>
  35. </filter-mapping></web-app>

spring配置文件:applicationContext.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="3.0"
  3. xmlns="http://java.sun.com/xml/ns/javaee"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  6. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  7. <display-name></display-name>
  8. <context-param>
  9. <param-name>contextConfigLocation</param-name>
  10. <param-value>classpath:applicationContext.xml</param-value>
  11. </context-param>
  12. <listener>
  13. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  14. </listener>
  15. <welcome-file-list>
  16. <welcome-file>index.jsp</welcome-file>
  17. </welcome-file-list>
  18. <filter>
  19. <filter-name>struts2</filter-name>
  20. <filter-class>
  21. org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  22. </filter-class>
  23. <init-param>
  24. <param-name>config</param-name>
  25. <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
  26. </init-param>
  27. </filter>
  28. <filter-mapping>
  29. <filter-name>struts2</filter-name>
  30. <url-pattern>*.action</url-pattern>
  31. </filter-mapping>
  32. <filter-mapping>
  33. <filter-name>struts2</filter-name>
  34. <url-pattern>*.jsp</url-pattern>
  35. </filter-mapping></web-app>

struts2.1配置文件struts.xml:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
  3. <struts>
  4. <constant name="struts.objectFactory" value="spring" />
  5. <package name="default" extends="struts-default" >
  6. <action name="userLogin" class="LoginAction">
  7. <result name="success">/success.jsp</result>
  8. <result name="input">/login.jsp</result>
  9. </action>
  10. </package>
  11. </struts>

LoginAction.java:

  1. public String execute() {
  2. // TODO Auto-generated method stub
  3. return SUCCESS;
  4. }

登陆页面 login.jsp:

  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
  2. <%@taglib prefix="s" uri="/struts-tags"%>
  3. <%
  4. String path = request.getContextPath();
  5. String basePath = request.getScheme() + "://"
  6. + request.getServerName() + ":" + request.getServerPort()
  7. + path + "/";
  8. %>
  9. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  10. <html>
  11. <head>
  12. <base href="<%=basePath%>">
  13. <title>My JSP 'login.jsp' starting page</title>
  14. <meta http-equiv="pragma" content="no-cache">
  15. <meta http-equiv="cache-control" content="no-cache">
  16. <meta http-equiv="expires" content="0">
  17. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  18. <meta http-equiv="description" content="This is my page">
  19. <!--
  20. <link rel="stylesheet" type="text/css" href="styles.css">
  21. -->
  22. </head>
  23. <body>
  24. This is my JSP page.
  25. <br>
  26. <s:form action="userLogin.action">
  27. <s:textfield name="username" label="用户名" />
  28. <s:password name="password" label="密码"></s:password>
  29. <s:submit type="button" value="登陆" />
  30. </s:form>
  31. </body>
  32. </html>

成功跳转页面 success.jsp:

  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
  2. <%@taglib prefix="s" uri="/struts-tags"%>
  3. <%
  4. String path = request.getContextPath();
  5. String basePath = request.getScheme() + "://"
  6. + request.getServerName() + ":" + request.getServerPort()
  7. + path + "/";
  8. %>
  9. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  10. <html>
  11. <head>
  12. <base href="<%=basePath%>">
  13. <title>My JSP 'success.jsp' starting page</title>
  14. <meta http-equiv="pragma" content="no-cache">
  15. <meta http-equiv="cache-control" content="no-cache">
  16. <meta http-equiv="expires" content="0">
  17. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  18. <meta http-equiv="description" content="This is my page">
  19. <!--
  20. <link rel="stylesheet" type="text/css" href="styles.css">
  21. -->
  22. </head>
  23. <body>
  24. This is my JSP page.
  25. <br> Welcome!
  26. <h5>
  27. <s:property value="username" />
  28. </h5>
  29. <br>
  30. <h6>
  31. <s:property value="password" />
  32. </h6>
  33. </body>
  34. </html>

这个是修改之后的正确代码,原来错误代码的struts.xml中的action的name是login,login.jsp中的action="login.action",将这两个action改成“userLogin”之后就没有问题了,改成Login也是可以的。不知道是什么问题,希望了解的大神们指点一下。

最新文章

  1. Docker知识-1
  2. IntelliJ IDEA 15 激活码 正版 可离线激活
  3. java环境配置
  4. XVI Open Cup named after E.V. Pankratiev. GP of SPB
  5. bzoj4702: 装箱游戏
  6. ExtJs之Ext.core.Element
  7. JAVA与图形界面开发(Applet应用程序、AWT库、Swing)
  8. EXCEL 建立工作薄与工作表
  9. [Node] 逃离回调地狱
  10. 为什么Underscore
  11. 第一百二十四节,JavaScriptCookie与存储
  12. head 命令 读取文件的前n行,默认查看文件的前十行
  13. English trip V1 - 23. Big and Bigger Teacher:Corrine Key: adjective comparisons 形容词 比较级
  14. 【LOJ】#2126. 「HAOI2015」数组游戏
  15. Java设计模式(9)适配器模式(Adapter模式)
  16. AS3 在不规则区域内拖动
  17. python 在Unicode和普通字符串 str 之间转换
  18. uwsgi的python2+3多版本共存实操使用virtualenv
  19. java内存占用问题(一)
  20. 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛

热门文章

  1. Hibernate 关于实体映射常用注解
  2. Angular表单的本地校验和远程校验
  3. 路由器分配的IP地址
  4. InnoDB并发事务
  5. mongodb数据文件结构——record是内嵌BSON的双向链表,多个record或索引组成extent
  6. xftp5+xshell5工具安装包分享
  7. Mac 系统安装redis服务
  8. linux shell 学习笔记--比较操作
  9. Memcache mutex设计模式
  10. 2016 ACM-ICPC 区域赛(大连站)题解