我的项目有问题。当我浏览http://localhost:8080/user/form
以显示UserForm时,会出现以下错误:
警告:找不到带有URI [/ user / form]的HTTP请求的映射 具有名称' userservice'
的DispatcherSe rvlet
此处归档userservice-servlet.xml
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd ">
<context:component-scan base-package="edu.java.spring.service.user.controller"></context:component-scan>
<context:component-scan base-package="edu.java.spring.service.user.dao"></context:component-scan>
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="1" />
<property name="suffix" value=".jsp" />
<property name="prefix" value="/user/" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingLocations">
<list>
<value>classpath:User.hbm.xml</value>
</list>
</property>
<property name="packagesToScan" value="edu.java.spring.service.user.model" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="url"
value="jdbc:derby:D:\PROJECTSPRING\userdb;create=true" />
<property name="username" value="" />
<property name="password" value="" />
</bean>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="contentType" value="text/plain"/>
</bean>
</beans>
此处归档UserRestServiceController.java
@Controller
public class UserRestServiceController {
@Autowired
private UserDao userDao;
@Autowired
private View jsonView;
@RequestMapping(value="/user/form,",method = RequestMethod.GET)
public ModelAndView user(){
// System.out.println("anh yeu em ");
return new ModelAndView("UserForm","User",new User());
}
@RequestMapping(value="/user/json/{username}")
public ModelAndView loadUser(@PathVariable("username")String name){
return new ModelAndView(jsonView,"data",userDao.loadUser(name));
}
}
此处file web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>userservice</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>userservice</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>userservice</servlet-name>
<url-pattern>*.xml</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
edu.java.spring.service.user.controller.CustomContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/userservice-servlet.xml</param-value>
</context-param>
</web-app>
答案 0 :(得分:0)
<property name="prefix" value="/user/" />
这意味着您已将JSP保存在webapp / user目录中?
尝试移入WEB-INF并检查。
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>