Spring应用程序在浏览器上获取空值

时间:2017-10-17 13:02:21

标签: spring-mvc

这是web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app id = "WebApp_ID" version = "3.0"
   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_3_0.xsd">
<display-name>First spring project</display-name>
    <servlet>
  <servlet-name>spring-dispatcher</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>spring-dispatcher</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>
   </web-app>

这是spring-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
   <context:component-scan base-package="com.wasik.controller"></context:component-scan>
  <mvc:annotation-driven/> 
  <bean id="viewResolver"
   class="org.springframework.web.servlet.view.InternalResourceViewResolver">
 <property name="prefix">
<value>/WEB-INF/</value> 
</property>
<property name="suffix">
<value>.jsp</value>
</property>     
   </bean>
   </beans>

这个控制器我在那里使用注释

package com.wasik.controller;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class mycontroller {
@RequestMapping(value="/admissionForm.html" , method=RequestMethod.GET)
public ModelAndView display(){

    ModelAndView view=new ModelAndView("AdmissionForm");

    return view;
}
@RequestMapping(value="/submitAdmissionForm", method=RequestMethod.POST)
public ModelAndView Success(@PathVariable Map<String, String>map) {

    ModelAndView  view =new ModelAndView ("AdmissionSuccess");
    String name=map.get("name");
    String password=map.get("password");
view.addObject("msg","hi "+name+ password);
return view;
}
}

之后我会使用用户名和密码这两个值

addmissionForm.jsp
<form action="/springWithFormValidation/submitAdmissionForm" method="POST">
Name<input type="text" name="name">
password<input type="test" name="password">
<input type="submit" value="submit">
</form>

最后在浏览器上填充

admissionSuccess.jsp

<p> successfully registered with following details</p>
<h2> ${msg}</h2>

0 个答案:

没有答案