日期:2014-05-18  浏览次数:20595 次

JSP怎么提交到struts2
HTML代码(提交到login.do) 当点击提交按钮的时候 就报404错误 

<form action="login.do" method="POST">
<%
if ( flag != null ) {
%>
<div id="cwxx" align="center" style="font-size:12px; background-color:#FF3366"> <%=flag %> </div>
<%
}
%>
   用户名:<input type="text" name="temail" onblur=""><br>
   密&nbsp;&nbsp;码:<input type="password" name="tpass"><br>
   <input type="submit" value="提交">
</form>



struts配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="login" method="login" class="com.mulan.struts.action.LoginAction">
<result name="success"></result>
</action>
<action name="register" method="register" class="com.mulan.struts.action.LoginAction">
<result name="success"></result>
</action>
</package>
</struts>



这是web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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">

<welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<context-param>
  <param-name>contextConfigLocation </param-name>
  <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>
   org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
</filter>
<filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>*.do</url-pattern>
</filter-mapping>

<resource-ref>
  <description>MySQL DataSource</description>
  <res-ref-name>jdbc/TestDB</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
   </resource-ref>
</web-app>

------解决方案--------------------
404说明框架和容器都正常运行,那么就是在web.xml中的action路径肯定没配置对,你直接访问action看能不能访问到
------解决方案--------------------
访问:http://localhost:端口号\你的项目名称\login.do
------解决方案--------------------
<result name="success"></