2016-08-01 11 views
0

im Versuch, den Namen in der Form und zeigt esEtat HTTP 404 - /mvc/traitementTwo.jsp - spring mvc

Der Controller eingegeben zu nutzen:

package yo; 

import javax.servlet.http.HttpServletRequest; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 

@Controller 
public class HelloWorldController { 

    @RequestMapping("/") 
    public String showPage(){ 
     return "helloworld"; 
     } 

    @RequestMapping("/showForm") 
    public String showForm(){ 
     return"form"; 
    } 
    @RequestMapping("/traitement") 
    public String processForm(){ 
     return"traitement"; 
    } 
    @RequestMapping("/traitementTwo") 
    public String caps(HttpServletRequest request,Model model){ 

     String theName=request.getParameter("s"); 
     String result="YO "+theName.toUpperCase(); 
     model.addAttribute("message", result); 
     return"helloworld"; 
    } 

} 

form.jsp:

<body> 
hello <form action="traitementTwo.jsp" method="GET"> 

    <input type="text" name="s" placeholder="who are u ?" /> 

    <input type="submit"/> 

    </form> 

</body> 
</html> 

helloworld.jsp:

<html> 
<body> 
    the time on the server is <%= new String("Hello World").toUpperCase() %> 
<br> 


    The message :${message} 

</body> 
</html> 

feder mvcdemo-Servlet:

<?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"> 

    <!-- Step 3: Add support for component scanning --> 
    <context:component-scan base-package="yo" /> 

    <!-- Step 4: Add support for conversion, formatting and validation support --> 
    <mvc:annotation-driven/> 

    <!-- Step 5: Define Spring MVC view resolver --> 
    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/view/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

</beans> 

web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
    id="WebApp_ID" version="3.1"> 

    <display-name>mvc</display-name> 

    <!-- Spring MVC Configs --> 

    <!-- Step 1: Configure Spring MVC Dispatcher Servlet --> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet --> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

</web-app> 

Output:

Etat HTTP 404 - /mvc/traitementTwo.jsp Typ Rapport d‘ 'état

Nachricht /mvc/traitementTwo.jsp

Beschreibung La ressource demandée n''est pas disponible.


Apache Tomcat/8.0.36

+0

wie hast du den * view-controller * von spring mvc konfiguriert? –

+0

werfen Sie einen Blick ich poste es –

+0

Ich beantwortete Ihre vorherige Frage .. es scheint, jetzt haben Sie ein anderes Problem? Anstatt meine Antwort abzuwählen und diese auf eine völlig andere Frage zu ändern, sollten Sie eine neue Frage dafür erstellen. – Pete

Antwort

1

Klingt wie Sie nicht Setup Ihre web.xml haben richtig die Servlet-Kontexte usw.

für das Vorhaben zu erstellen Siehe: https://www.mkyong.com/spring-mvc/spring-mvc-and-list-example/

Es hat die folgende Struktur innerhalb src> Haupt-> Webapp

/- web.xml

/- mvc-Dispatcher-servlet.xml

/pages (Verzeichnis, in die JSP-Seiten speichern)

Ansonsten bitte Ihre Webapp oder Feder-Boot-Konfiguration erstellen, um zu bestätigen, dass Sie es richtig eingerichtet haben .

+0

werfen Sie einen Blick ich poste es –

0

Sie haben Spring-MVC zu entwickeln, aber Sie haben nicht die Spring MVC XML-Konfigurationsdatei. Sie sollten eine feder mvc.xml schaffen eine Botschaft über den Frühling mvc

+0

werfen Sie einen Blick ich poste es –

0

Ok zu konfigurieren, ich glaube, ich weiß, was das Problem .. in Ihrem form.jsp ist Sie hatte:

<form action="traitementTwo.jsp" method="GET"> 

sein sollte:

<form action="traitementTwo" method="GET"> 
+0

@ AymanR'bati bist du sicher ..? Ich habe Ihren Code tatsächlich in meine Umgebung geschrieben, implementiert und in das gleiche Problem gebracht. Dann habe ich es in traitementTwo geändert und es hat funktioniert ... – Pete