【发布时间】:2015-03-18 02:01:16
【问题描述】:
大家好,我试图从其他命题中为我的代码找到解决方案但徒劳无功:/所以这是我的代码寻求帮助:/ spring-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.pfa.controller" />
<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>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>FirstSpringApp</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>
登录控制器
package com.pfa.controller;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.portlet.ModelAndView;
@Controller
public class LoginController {
@RequestMapping(value="/admissionForm.html", method = RequestMethod.GET)
public ModelAndView getAdmissionForm() {
ModelAndView model = new ModelAndView("AdmissionForm");
return model;
}
@RequestMapping(value="/submitadmissionForm.html", method = RequestMethod.POST)
public ModelAndView submitAdmissionForm(@RequestParam Map<String,String> reqPar) {
String name = reqPar.get("studentName");
String hobby = reqPar.get("hobby");
ModelAndView model = new ModelAndView("AdmissionSuccess");
model.addObject("msg","Details submitted by you:: Name: "+name+ ", Hobby: " + hobby);
return model;
}
}
AdmissionForm.html
<html>
<body>
<h1> STUDENT ADMISSION FORM FOR ENGINEERING COURSES</h1>
<form action="/FirstSpringApp/submitadmissionForm.html" method="post">
<p>
Student's Name : <input type="text" name="studentName" />
</p>
<p>
Student's Hobby : <input type="text" name="studentHobby" />
</p>
<input type="submit" value="Submit this form by clicking here" />
</form>
</body>
</html>
AdmissionSucces.html
<html>
<body>
<h1>Congratulations!! the Engineering college has processed your Application form successfully</h1>
<h2>${msgddd}</h2>
</body>
</html>
【问题讨论】:
-
您要访问哪个网址?在您的问题中发布来自 Spring in 的确切日志消息。
-
编辑您的问题。不要发布不是答案的答案。
标签: java spring jsp spring-mvc servlets