找不到此 localhost 页面找不到 Web 地址对应的网页: http://localhost:8009/StudentManagerSSM/WEB-INF/views/student/student_list.jsp HTTP ERROR 404
时间: 2023-10-04 20:08:11 浏览: 458
这个错误说明你访问的本地服务器地址不存在或者该地址对应的页面不存在。可能原因有以下几种:
1. 你的本地服务器没有启动或者启动失败。
2. 你访问的网址不正确。
3. 你访问的页面不存在或者路径不正确。
你可以尝试以下步骤来解决这个问题:
1. 确认本地服务器是否已经启动,以及端口号是否正确。
2. 检查你访问的网址是否正确,包括协议、地址、端口号、路径等。
3. 检查你访问的页面是否存在,或者路径是否正确。可以查看本地服务器中对应的目录和文件是否存在。
4. 如果以上步骤都没有解决问题,可以尝试重启本地服务器或者重新部署项目。
相关问题
不是springboot项目,是一个springmvc架构的web项目
好的,以下是一个简单的Spring MVC项目,集成了Eureka和Feign,您可以参考:
1. 首先,需要在pom.xml中添加以下依赖:
```xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
```
2. 在web.xml中添加DispatcherServlet配置
```xml
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
```
3. 创建spring-mvc.xml文件,并添加以下配置:
```xml
<context:component-scan base-package="com.example.controller" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate" />
<bean id="feignContext" class="org.springframework.cloud.openfeign.FeignContext">
<constructor-arg>
<map />
</constructor-arg>
</bean>
<bean id="feignBuilder" class="org.springframework.cloud.openfeign.FeignClientBuilder" />
<bean id="serviceProviderClient" class="org.springframework.cloud.openfeign.FeignClientFactoryBean"
p:name="service-provider" />
<bean id="serviceConsumerController" class="com.example.controller.ServiceConsumerController">
<constructor-arg ref="restTemplate" />
<constructor-arg ref="feignContext" />
<constructor-arg ref="feignBuilder" />
</bean>
<bean id="serviceProviderClientFallback" class="com.example.controller.ServiceProviderClientFallback" />
<bean id="hystrixFeignBuilder" class="org.springframework.cloud.netflix.feign.FeignHystrixBuilder">
<constructor-arg ref="serviceProviderClientFallback" />
</bean>
```
4. 创建一个Feign客户端接口,用于定义需要调用的服务API
```java
@FeignClient(name = "service-provider", fallbackFactory = ServiceProviderClientFallbackFactory.class)
public interface ServiceProviderClient {
@GetMapping("/hello")
String hello();
}
```
5. 在控制器中注入ServiceProviderClient,并调用其hello方法
```java
@Controller
public class ServiceConsumerController {
@Autowired
private RestTemplate restTemplate;
@Autowired
private FeignContext feignContext;
@Autowired
private FeignClientBuilder feignBuilder;
private ServiceProviderClient serviceProviderClient;
public ServiceConsumerController(RestTemplate restTemplate, FeignContext feignContext, FeignClientBuilder feignBuilder) {
this.restTemplate = restTemplate;
this.feignContext = feignContext;
this.feignBuilder = feignBuilder;
this.serviceProviderClient = feignBuilder.target(ServiceProviderClient.class, "http://service-provider");
}
@RequestMapping("/hello")
public String hello(Model model) {
// 使用RestTemplate调用服务提供者
String result = restTemplate.getForObject("http://service-provider/hello", String.class);
model.addAttribute("result1", result);
// 使用Feign调用服务提供者
serviceProviderClient = feignBuilder.target(ServiceProviderClient.class, "http://service-provider");
result = serviceProviderClient.hello();
model.addAttribute("result2", result);
return "hello";
}
}
```
6. 创建ServiceProviderClientFallbackFactory类,用于定义Feign客户端的fallback逻辑
```java
@Component
public class ServiceProviderClientFallbackFactory implements FallbackFactory<ServiceProviderClient> {
@Override
public ServiceProviderClient create(Throwable throwable) {
return new ServiceProviderClient() {
@Override
public String hello() {
return "Fallback: " + throwable.getMessage();
}
};
}
}
```
7. 创建ServiceProviderClientFallback类,用于定义Feign客户端的fallback逻辑
```java
@Component
public class ServiceProviderClientFallback implements ServiceProviderClient {
@Override
public String hello() {
return "Fallback: Service Provider is not available";
}
}
```
8. 在application.properties中配置Eureka和Feign
```properties
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
feign.client.config.default.connectTimeout=5000
feign.client.config.default.readTimeout=5000
```
9. 启动Eureka服务器和服务提供者,然后启动服务消费者,访问http://localhost:8080/hello即可看到服务提供者返回的结果。
希望这个例子能够帮助到您!
Web.xml ,Springmvc-config.xml ,Spring-mybatis.xml ,Applicationcontext.xml 四个配置文件主要代码功能描述及代码
1. `web.xml`:
`web.xml` 是 Java Web 应用程序的配置文件,用于配置 Servlet、Filter、Listener 等 Web 组件。主要功能如下:
- 配置 Servlet 和 Servlet 映射。
- 配置 Filter 和 Filter 映射。
- 配置 Listener。
- 配置错误页面。
- 配置 Session 超时时间。
- 配置上下文参数等。
示例代码:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<display-name>MyWebApp</display-name>
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>com.example.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/myservlet/*</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
</web-app>
```
2. `springmvc-config.xml`:
`springmvc-config.xml` 是 Spring MVC 框架的配置文件,用于配置 Spring MVC 相关的组件,如视图解析器、拦截器等。主要功能如下:
- 配置 Spring MVC 的 HandlerMapping 和 HandlerAdapter。
- 配置视图解析器。
- 配置拦截器。
- 配置文件上传解析器等。
示例代码:
```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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<mvc:interceptors>
<bean class="com.example.MyInterceptor"/>
</mvc:interceptors>
</beans>
```
3. `spring-mybatis.xml`:
`spring-mybatis.xml` 是 Spring 整合 MyBatis 框架的配置文件,用于配置 MyBatis 相关的组件,如数据源、SqlSessionFactory、MapperScannerConfigurer 等。主要功能如下:
- 配置数据源。
- 配置 SqlSessionFactory。
- 配置 MapperScannerConfigurer。
- 配置事务管理器等。
示例代码:
```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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="com.example"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="user" value="root"/>
<property name="password" value="123456"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.example.mapper"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven/>
</beans>
```
4. `applicationContext.xml`:
`applicationContext.xml` 是 Spring 的核心配置文件,用于配置 Spring 容器中的 Bean。主要功能如下:
- 配置数据源、事务管理器等基础组件。
- 配置 Service、DAO 等业务组件。
- 配置 AOP、声明式事务等。
- 配置定时任务等。
示例代码:
```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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="com.example"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="user" value="root"/>
<property name="password" value="123456"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven/>
<bean id="userService" class="com.example.UserService">
<property name="userDao" ref="userDao"/>
</bean>
<bean id="userDao" class="com.example.UserDao">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)