2013-03-26 2 views
1

Я пытаюсь некоторые образцы в весеннем mvc.I имеет три класса Student.java и StudentController.java следующийНет appenders не может быть найдено для регистратора

Student.java

package mvc1; 
public class Student { 
    private Integer age; 
    private String name; 
    private Integer id; 

    public void setAge(Integer age) { 
     this.age = age; 
    } 
    public Integer getAge() { 
     return age; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 
    public String getName() { 
     return name; 
    } 

    public void setId(Integer id) { 
     this.id = id; 
    } 
    public Integer getId() { 
     return id; 
    } 
} 

StudentController.java

package mvc1; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.ModelAttribute; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.servlet.ModelAndView; 
import org.springframework.ui.ModelMap; 

@Controller 
@RequestMapping("login.do") 
public class StudentController { 

    @RequestMapping(value = "/student", method = RequestMethod.GET) 
    public ModelAndView student() { 
     return new ModelAndView("student", "command", new Student()); 
    } 

    @RequestMapping(value = "/addStudent", method = RequestMethod.POST) 
    public String addStudent(@ModelAttribute("SpringWeb")Student student, 
    ModelMap model) { 
     model.addAttribute("name", student.getName()); 
     model.addAttribute("age", student.getAge()); 
     model.addAttribute("id", student.getId()); 

    return "result"; 
    } 
} 

у меня есть сервлет XML-файл как HelloWeb-servlet.xml, который, как следовать

<?xml version="1.0" encoding="UTF-8"?> 
<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" 
    xsi:schemaLocation=" 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="Servee" /> 

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

</beans> 

и файл web.xml следующим образом ...

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/DispatcherServlet.xml</param-value> 
</context-param> 


    <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener- 
     class> 
    </listener> 

<servlet> 
    <servlet-name>HelloWeb</servlet-name> 
    <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
    <load-on-startup>2</load-on-startup> 

</servlet> 

<servlet-mapping> 
    <servlet-name>HelloWeb</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

и student.jsp и result.jsp файлы хранятся в mvc11 пакете

student.jsp

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<h2>Student Information</h2> 
<form:form method="POST" action="/Spring/mvc1/addStudent"> 
    <table> 
    <tr> 
     <td><form:label path="name">Name</form:label></td> 
     <td><form:input path="name" /></td> 
    </tr> 
    <tr> 
     <td><form:label path="age">Age</form:label></td> 
     <td><form:input path="age" /></td> 
    </tr> 
    <tr> 
     <td><form:label path="id">id</form:label></td> 
     <td><form:input path="id" /></td> 
    </tr> 
    <tr> 
     <td colspan="2"> 
      <input type="submit" value="Submit"/> 
     </td> 
    </tr> 
</table> 
</form:form> 
</body> 
</html> 

result.jsp

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<h2>Submitted Student Information</h2> 
    <table> 
    <tr> 
     <td>Name</td> 
     <td>${name}</td> 
    </tr> 
    <tr> 
     <td>Age</td> 
     <td>${age}</td> 
    </tr> 
    <tr> 
     <td>ID</td> 
     <td>${id}</td> 
    </tr> 
</table> 
</body> 
</html> 

При запуске нины весной программа я получаю сообщение предупреждения следующего

log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). 
log4j:WARN Please initialize the log4j system properly. 
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 

и сообщение об ошибке, как

The requested resource (/Spring/mvc11/student.jsp) is not available. 

HelloWeb-servlet.xml хранится под WEB-INF.I сослалась много источник, но не смог исправить it.Can кто-нибудь помочь мне с этим ...

+2

Предупреждения касаются объекта log4j файл, который не найден, но ошибка, о которой вы упоминаете, не имеет ничего общего с этим. – benzonico

ответ

0

Похоже, существует множество проблем

  1. Пакет mvc1 не добавлен в component-scan. решение: Добавьте следующую строку в HelloWeb-Servlet.xml

  2. @RequestMapping("login.do") аннотаций в StudentController не имеет никакого смысла, удалить его

  3. У вас есть отображение для URL /student, но пытается получить доступ к /Spring/mvc11/student.jsp , либо изменить RequestMapping, либо запрошенный url

Смежные вопросы

 Смежные вопросы