请问为什么我总是找不到响应的action呢?总是出现404的错误!

06-02-27 big1980
我的xml是这样申明的

// 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>

<servlet>
<servlet-name>siapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>siapp</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

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

<taglib>
<taglib-uri>/spring</taglib-uri>
<taglib-location>/WEB-INF/spring.tld</taglib-location>
</taglib>

</web-app>
==========================================================
siapp-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans> 

<bean id="SiappValidator" class="web.SiappValidator"/>

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename"><value>messages</value></property>
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/login.do">SiappController</prop>
</props>
</property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
<property name="viewClass"> 
<value>org.springframework.web.servlet.view.InternalResourceView</value> 
</property> 
<property name="prefix"> 
<value>/WEB-INF/jsp/</value> 
</property> 
<property name="suffix"> 
<value>.jsp</value> 
</property> 
</bean> 

<bean id="SiappController" class="web.SiappController">
<property name="commandClass"> 
<value>web.SiappForm</value> 
</property> 
<property name="success_view"> 
<value>/WEB-INF/jsp/login.jsp</value> 
</property> 
<property name="fail_view"> 
<value>/index.jsp</value> 
</property> 
</bean> 

</beans>
=======================================================
index.jsp
<%@page contentType="text/html;charset=GB2312"%> 
<html> 
<head><title>Login</title></head> 
<body> 
请输入使用者名称与密码:<p> 
<form name="loginform" action="/login.do" method="post"> 
名称 <input type="text" name="username"/><br> 
密码 <input type="password" name="password"/><br> 
<input type="submit" value="确定"/> 
</form> 
注意:输入错误会再回到这个页面中。 
</body> 
</html> 
=======================================================
SiappController.java
package web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import java.io.IOException;
import java.net.BindException;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class SiappController extends SimpleFormController {
private String fail_view;
private String success_view;

/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());

protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object cmd, BindException ex)
throws ServletException, IOException {

String now = (new java.util.Date()).toString();
logger.info("returning hello view with " + now);

SiappForm form = (SiappForm)cmd;

Map resultModel = new HashMap();
resultModel.put("now", now);
resultModel.put("user", "bighead");

if("1".equals(form.getUsername()) && 
"1".equals(form.getPassword())) { 
return new ModelAndView(this.getSuccessView(),"model", resultModel); 
} 
else { 
return new ModelAndView(this.getFormView()); 
} 
}

public String getFail_view() {
return fail_view;
}

public String getSuccess_view() {
return success_view;
}

public void setFail_view(String argString) {
fail_view = argString;
}

public void setSuccess_view(String argString) {
success_view = argString;
}
}
==========================================================
login.jsp
<html> 
<head><title>Login Success</title></head> 
<body> 
<H1> Hello, ${model.user}!!</H2> 
This is your secret gift. TIME:${model.now}
</body> 
</html> 
==========================================================
搞不懂这到底是为什么?大家帮忙看看吧!

<p>

flyhawk_xjtu
2006-03-16 14:27
找不到action一般是因为config文件没有写好。你去检查一下你的congig文件中form和action是否对应配置

猜你喜欢