gpt4 book ai didi

java - org.springframework.web.servlet.PageNotFound :1108

转载 作者:行者123 更新时间:2023-12-01 12:36:31 25 4
gpt4 key购买 nike

我尝试用我在 stackoverflow 中遇到的所有解决方案来解决这个问题,但没有一个对我有用

这是我的 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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

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


</web-app>

这是我的 servlet-context-xml:

<!-- Enable @Controller annotation support -->
<mvc:annotation-driven />

<!-- Esta etiqueta es para mapear carpetas dentro de src/main/webapp
de lo contrario el servidor no las reconoceria
-->
<!-- <mvc:resources mapping="/css/**" location="/css/" /> -->


<!-- Map simple view name such as "test" into /WEB-INF/PAGE/test.jsp -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/page/" />
<property name="suffix" value=".jsp" />
</bean>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views" />
</bean>

<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>


<!-- Scan classpath for annotations (eg: @Service, @Repository etc) -->
<context:component-scan base-package="com.ieea.dao" />
<context:component-scan base-package="com.ieea.controller" />
<!-- Contenido agregador -->

<mvc:annotation-driven />




<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
</bean>
<!-- Contenido agregador -->

<!-- JDBC Data Source. It is assumed you have MySQL running on localhost
port 3306 with username root and blank password. Change below if it's not
the case -->

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">

<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/******" />
<property name="username" value="*****" />
<property name="password" value="*****" />
<property name="validationQuery" value="SELECT 1" />

</bean>


<!-- Hibernate Session Factory -->
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan">
<array>
<value>com.ieea.domain</value>
</array>
</property>



<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
<!-- <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect </value> -->

</property>
</bean>

<!-- Hibernate Transaction Manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory" />

</bean>

<!-- Activates annotation based transaction management -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>

Controller :

@Controller
public class UsuarioController {

@Autowired UsuarioDAOImpl usuarioDAO;

@RequestMapping(value = "lista", method = RequestMethod.GET)
public String testReporte(Model model) {

try {
System.out.println("Entre");
List<Usuario> lista = usuarioDAO.encontrarTodosUsuarios();
model.addAttribute("lista", lista);

} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

return "index";
}

}

我认为问题出在 web.xml 或 servlet-context.xml 中我不知道我的应用程序发生了什么, Spring 的其他应用程序永远不会导致此问题。

org.springframework.web.servlet.PageNotFound:1108 - 在名为“appServlet”的 DispatcherServlet 中未找到带有 URI [/usuariosTest/] 的 HTTP 请求的映射

最佳答案

您可能没有提供“/”的请求映射,即启动网址。

在 Controller 中放置一个“/” url 映射。您需要首先将其部署在服务器上并启动服务器,然后在浏览器中点击应用程序 URL。

@RequestMapping(value = "/", method = RequestMethod.GET)
public String testReporte(Model model) {

try {
System.out.println("Entre");
List<Usuario> lista = usuarioDAO.encontrarTodosUsuarios();
model.addAttribute("lista", lista);

} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

return "index";
}

关于java - org.springframework.web.servlet.PageNotFound :1108,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25534644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com