The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Tried the code like 10 times...
您好,这是我的Spring MVC Hello Name示例。
<form action="./hello.ds">
Name:<input type="text" name="name"/>
<input type="submit" value="say Hello..."/>
</form>
<!-- success.jsp-->
${msg}
<?xml version="1.0" encoding="UTF-8"?>
<web-app id = "WebApp_ID" version = "2.4"
xmlns = "http://java.sun.com/xml/ns/j2ee"
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.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">
<display-name>Spring MVC Application</display-name>
<welcome-file-list>
<welcome-file>Index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>*.ds</url-pattern>
</servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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="controller.HelloControler" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean id="hc" class="controller.HelloControler"/>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="./hello.ds">hc</prop>
</props>
</property>
</bean>
<bean class="import org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="./"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
package controller;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class HelloController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res) throws Exception {
String name = req.getParameter("name");
Map m = new HashMap();
m.put("msg", "Hello..." + name);
ModelAndView mav = new ModelAndView("success",m);
System.out.println("in controller class...");
return mav;
}
}
''''。xml文件在/ WEB-INF / lib文件夹中。 HelloController在控制器包中 MVC_Project_1是项目的名称。 .jsp页面位于WebContent中。 ''''
''''''如果您输入John作为输入,将输出“ Hello ... John” Index.jsp页面? ''''