目录
首先,我们还是来先建一个项目:Maven版本选择1.0


然后等加载完项目后,添加到tomcat服务器里。
但我们有时候会看到JSP页面报了个莫名其妙的错误。说是没有找到servlet,那么我们需要在pom.xml中配置下这个jar包既可以。

往pom.xml中添加:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
然后在同步升级下web的版本,需要在.settings文件包中org.eclipse.wst.common.project.facet.core.xml中进行版本同步升级为3.1。
最后就是maven update. 准备就绪了。
第一步:我们所需要的几个类,让程序先跑起来。
dao:
package com.exception.dao;
import java.util.Date;
import org.springframework.stereotype.Repository;
@Repository
public class UserDao {
public void show() throws Exception{
System.out.println("user dao is running");
}
}
service:
package com.exception.services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.exception.dao.UserDao;
@Service
public class UserService {
@Autowired
private UserDao userDao;
public void show() {
System.out.println("-----user service is running");
userDao.show();
}
}
controller:
package com.exception.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.exception.services.UserService;
@Controller
@RequestMapping("user")
public class UserController extends BaseController {
@Autowired
private UserService userService;
@RequestMapping("show")
public String show() {
userService.show();
return "show";
}
}
show.jsp :
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Add User</title>
<style type="text/css">
</style>
</head>
<body>
<h2>~~~~ welcome to show page ~~~~</h2>
</body>
<script type="text/javascript">
</script>
</html>
加入tomcat,进行运行测试。http://localhost:80

最低0.47元/天 解锁文章
3639

被折叠的 条评论
为什么被折叠?



