2013-04-28 8 views
0

J'essayais d'exécuter un exemple d'application Spring, mais je n'arrive pas à le configurer. J'ai cherché mon problème mais tout semble bien pour moi.Configuration du ressort

Web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    id="WebApp_ID" version="2.5"> 
    <display-name>Spring Hello World</display-name> 
    <welcome-file-list> 
     <welcome-file>/</welcome-file> 
    </welcome-file-list> 

    <servlet> 
     <servlet-name>springDispatcher</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring-context.xml</param-value> 
     </init-param>   
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>springDispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

fichier Controller dans com.fyp.ptma.controller

@Controller 
public class HelloWorldController { 

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

    @RequestMapping(value = "/hi", method = RequestMethod.GET) 
    public String hi(@RequestParam("name") String name, Model model) { 
     String message = "Hi " + name + "!"; 
     model.addAttribute("message", message); 
     return "hi"; 
    } 

} 

ressort context.xml

<?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:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     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"> 

    <context:component-scan base-package="com.fyp.ptma.controller" /> 
    <mvc:annotation-driven /> 

    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/views/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

</beans> 

hello.jsp dans WEB-INF /views/hello.jsp

<html> 
<head> 
<title>Home</title> 
</head> 
<body> 
    <h1>Hello World!</h1> 

<hr/> 

    <form action="hi"> 
     Name: <input type="text" name="name"> <input type="submit" value="Submit"> 
    </form> 

</body> 
</html> 

fichier ptma.xml dans tomcat à conf/Catalina/localhost/ptma.xml de

<?xml version="1.0" encoding="utf-8"?> 
<Context docBase="/Volumes/DataDrive/FYP/TestMonkeyAppWeb‬/WebContent‬‪" debug="0" crossContext="true" reloadable="true" > 
</Context> 

accéder à mon projet localhost: 8080/AMPT/ mais il dit état HTTP 404 et le journal tomcat semblent fonctionner bien.

+0

votre formulaire n'a aucun attribut de méthode. –

+0

attribut de formulaire préoccupation avec quelque chose quand je soumets formulaire, mon problème est ma page même pas ouvert –

Répondre

1

Le mappage du fichier de bienvenue dans votre fichier web.xml semble incorrect. Changez-le en quelque chose comme index.jsp, créez un fichier avec ce nom à la racine de votre application et redirigez-le vers votre premier contrôleur.

+0

j'ai index.jsp fichier sur mon webcontent/index.jsp, mais les fichiers dans webcontent/WEB-INF/hello.jsp, ne pas ouvrir lorsque je navigue sur localhost: 8080/ptma/hello indique le statut HTTP 404 –

+0

Oui, vous avez mappé les vues jsp à "/ WEB-INF/views /", elles doivent donc être stockées dans ce répertoire. – Stefan

+0

désolé je corrige ils sont dans WEB-INF/views/pas dans WEB-INF/ –

Questions connexes