Простой пример Hello Name с использованием Spring MVC - PullRequest
0 голосов
/ 06 июля 2019
 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 World ...

<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.'' ''

'' '' «Hello ... John» будет выводиться, если Джон введен в качестве ввода на страницу Index.jsp ?.'' ''

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...