【发布时间】:2015-12-03 17:17:19
【问题描述】:
这里我使用 SimpleUrlHandlerMapping 的 urlMap 属性与控制器进行映射,但它不与控制器进行映射。这里我已经放置了调度程序、Jsp 和控制器的代码。
我已包含以下 Jar 文件--:
com.springsource.org.apache.commons.fileupload-1.2.0.jar
com.springsource.org.apache.commons.httpclient-3.1.0.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
com.springsource.org.codehaus.jackson.mapper-1.0.0.jar
jmxtools-1.2.1.jar
jstl-1.2 (1).jar
org.springframework.asm-3.0.1.RELEASE-A.jar
org.springframework.beans-3.0.1.RELEASE-A.jar
org.springframework.context-3.0.1.RELEASE-A.jar
org.springframework.core-3.0.1.RELEASE-A.jar
org.springframework.expression-3.0.1.RELEASE-A.jar
org.springframework.oxm-3.0.1.RELEASE-A.jar
org.springframework.web-3.0.1.RELEASE-A.jar
org.springframework.web.portlet-3.0.1.RELEASE-A.jar
org.springframework.web.servlet-3.0.1.RELEASE-A.jar
org.springframework.web.struts-3.0.1.RELEASE-A.jar
spring-webmvc-3.0.5.RELEASE.jar
调度程序-servlet.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/JSPpages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/Registration.html">
<ref bean="RegistrationCon" />
</entry>
</map>
</property>
</bean>
<bean id="RegistrationCon" class="controllers.registrationController.RegistrationController">
<property name="commandName">
<value>RegistrationBean</value>
</property>
<property name="commandClass">
<value>formBeans.registrationBean.RegistrationBean</value>
</property>
<property name="sessionForm">
<value>false</value>
</property>
<property name="formView">
<value>Registration</value>
</property>
<property name="successView">
<value>RegistrationSuccess</value>
</property>
</bean>
</beans>
注册控制器:
package controllers.registrationController;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import formBeans.registrationBean.RegistrationBean;
@SuppressWarnings("deprecation")
public class RegistrationController extends SimpleFormController {
protected ModelAndView onSubmit(HttpServletRequest req,HttpServletResponse res,Object command)throws ServletException //--OnSubmit Method Starts--//
{
System.out.println("In controller");
RegistrationBean regBean = (RegistrationBean) command;
String loginName=regBean.getLoginId();
System.out.println("Name---->"+loginName);
String pwd=req.getParameter("pwd");
System.out.println("PassWord---->"+pwd);
ArrayList<String> al=new ArrayList<String>();
al.add(loginName);
al.add(pwd);
ModelAndView mav=new ModelAndView("/RegistrationSuccess");
mav.addObject("ArrayList",al);
mav.addObject("regBean",regBean);
return mav;
}
}
注册(JSP):
<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head><title>User Personal Details</title>
<style>
table, th{
border: 1px solid black;
}
label{
font-family: "Trebuchet MS", Verdana, Halvetica, Arial;
font-size: 12px;
color: blue;
}
.textfield {
width: 250px;
border: 1px solid #AF9D72;
background-color: #F2ECD7;
}
</style></head>
<body bgcolor="#DDDDDD">
<h3>User Registration</h3>
<br/>
<form:form commandName="RegistrationBean" method="POST" name="RegistrationBean">
<div align="center" style="width:100%; height:100%">
<table style="height:250px; width:400px">
<tr>
<th>Heading</th>
<th>Input</th>
</tr>
<tr>
<td align="left"><label>Name:</label></td>
<td><form:input path="loginId" class="textfield"/></td>
</tr>
<tr>
<td align="left"><label>Password:</label></td>
<td><form:input path="pwd" class="textfield"/></td>
</tr>
<tr>
<td align="left"><label>Confirm Password:</label></td>
<td><form:input path="cpwd" class="textfield"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Save"/></td>
</tr>
</table>
</div>
</form:form>
</body>
</html>
【问题讨论】: