关于Spring MVC中action竟然没被调用。大家看看 源代码在此
问题就是在点击了main页面中的按钮后能够调到rlt这个页面,但是WelComeAction根本就没运行,System.out.println("%%%%%%%%%%%%%%%%%%%");这就都没运行
还有就是通过request.getParameter("prama1")我能获得页面中id为prama1这个文本框中的内容吗??
还有就是通过request.getParameter("prama1")我能获得页面中id为prama1这个文本框中的内容吗??
<?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>springmail</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmail-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmail</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/main.jsp</welcome-file>
</welcome-file-list><?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="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="main.do">welcome</prop>
</props>
</property>
</bean>
<bean id="welcome" class= "com.action.WelComeAction">
<property name="commandClass">
<value>com.po.mailservice</value>
</property>
<property name="formView" value="main" />
<property name="successView" value="rlt" />
</bean>
</beans> package com.action;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
public class WelComeAction extends SimpleFormController{
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response){
System.out.println("%%%%%%%%%%%%%%%%%%%");
String pra1 = request.getParameter("prama1");
String pra2 = request.getParameter("prama2");
System.out.println("!!!!!!!!!!!!!!!!!!!!!!:"+pra1+"@@@@@:"+pra2);
HashMap tojsp = new HashMap();
tojsp.put("pra1", request.getParameter("prama1"));
tojsp.put("pra2", request.getParameter("prama2"));
tojsp.put("pra3", "dfe");
tojsp.put("pra4","hgds");
return new ModelAndView(this.getSuccessView(),"tojsp",tojsp);
}
}
<%@ page language="java" pageEncoding="GB2312" contentType="text/html; charset=GB2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<form action="./main.do" method="post">
参数1:<input id="prama1" type="text" value="s"><br>
参数2:<input id="prama2" type="text" value="dfz"><br>
<input type="submit">
</form>
</body>
</html>
...全文
相关推荐
Spring 2.5.6介绍(九)——spring中没介绍的东西
NULL 博文链接:https://zpx138332.iteye.com/blog/1018900
Spring In Action 4 源代码
源代码 实例代码
Spring in Action 第四版
Spring in Action 最新第四版完整本,MEAP预览版,Manning即将上市
通过表单提交实现调用不同的action方法
可以在具体的Action实现类里增加新的方法(这些方法都是无参和公有的,都有一个String的返回类型),然后在url上指定这次请求调用哪个方法 有源代码,有注释,配置文档也配置好了
Spring in Action 4th 英文版及完整各章源代码
Spring in Action 4th,第4版英文版PDF,非扫描版,文字可拷贝,以及第1章到21章各章的源代码。


Web 开发
