日期:2014-05-20  浏览次数:21100 次

【struts1.2】我又测试不通了..
之前有个问题,也是我问的已经解决了。
http://topic.csdn.net/u/20110922/11/f33791c6-ff7d-4f75-9424-34770c5b01cd.html

现在又出现另一个问题了...我完全按照之前的写法写的,主页能进去但是每次提交就不行了.
上代码

form
HTML code
<form id="form1" name="login" method="post" action="/LoginAction.do?method=Login">


web.xml
XML code
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
      <servlet>
       <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/struts-config.xml</param-value>
    </init-param>
    <init-param>
       <param-name>debug</param-name>
    <param-value>2</param-value>
    </init-param>
     <load-on-startup>0</load-on-startup>
    </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>Login.jsp</welcome-file>
  </welcome-file-list>
</web-app>


struts-config.xml
XML code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
    "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
    <data-sources></data-sources>
    <global-exceptions></global-exceptions>
    <global-forwards></global-forwards>
    <action-mappings>
        <action path="/LoginAction" type="com.dsxx.Action.LoginAction"
            parameter="method">
            <forward name="loginsuccess" path="/index.jsp"></forward>
            <forward name="loginfail" path="/fail.html"></forward>
        </action>
    </action-mappings>
</struts-config>



LoginAction.java
Java code
package com.dsxx.Action;

import javax.servlet.http.*;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LoginAction extends Action{
    public ActionForward Login(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response){
        ActionForward forward=new ActionForward();
        forward=mapping.findForward("loginfail");
        return forward;
    }
}


每次点提交就会在这个页面
http://localhost:8080/LoginAction.do?method=Login
然后一片空白,myeclipset的控制台也不报错...
而且我想在LoginAction中用System.out.println("1")也不出东西,看来是没有进入Action啊
求指点啊...


------解决方案--------------------
http://localhost:8080/LoginAction.do?method=Login
这个路径缺少项目名称吧
试试这个
<form id="form1" name="login" method="post" action="./LoginAction.do?method=Login">