菜单->file->new->project
image.png取个项目名点击finish
image.png初始的项目结构是这样的
image.png整理项目结构
将src设置为普通的文件夹
image.png设置为源文件类型
image.png整理之后的项目结构
image.png配置tomcat服务
image.png image.pngimage.png
点击Apply->ok
配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
配置dispatcher.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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--指明 controller 所在包,并扫描其中的注解-->
<context:component-scan base-package="com.zhangfei.controller"/>
<!-- 静态资源(js、image等)的访问 -->
<mvc:default-servlet-handler/>
<!-- 开启注解 -->
<mvc:annotation-driven/>
<!--ViewResolver 视图解析器-->
<!--用于支持Servlet、JSP视图解析-->
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
创建一个DemoController
package com.yide.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Created by yide on 2018/11/7.
*/
@Controller
public class DemoController {
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(){
System.out.println("进来了");
return "test";
}
}
在WEN-INF下创建一个test.jsp
<%--
Created by IntelliJ IDEA.
User: yide
Date: 2018/11/7
Time: 下午2:12
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<h1>测试页面</h1>
</body>
</html>
启动项目
image.png访问接口
image.png我们发现并没有跳到test.jsp页面
解决方法
image.png image.png image.png image.pngimage.png
选择web所在的路径
image.png image.png配置好之后点击Apply->ok
启动项目 访问接口
image.png- 500 服务器错误也就是说进入我们写的接口了
- 具体看下报的什么错误 org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
大概的意思是找不到javax/servlet/jsp/jstl/core/Config这个类 此时我们首先想到的应该是少jar包
网友评论