- 创建web项目
- 复制静态页面的html, css, js,- 图片等等到动态工程的web目录下
- 测试动态项目能否正常启动,在该动态项目中,复制过来的html页面能否正常打开。
- 创建jsp页面
- 将html页面上的代码复制到jsp文件中,保留jsp文件第一行代码
- 运行服务器,看jsp文件是否能正常显示
- 创建页面对应servlet,实现页面跳转和数据接收
HomeServlet.java
req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
CompanyService companyService = new CompanyService();
NavService navService = new NavService();
NewsService newsService = new NewsService();
NewsTypeService newsTypeService = new NewsTypeService();
ProductService productService = new ProductService();
ProductTypeService productTypeService = new ProductTypeService();
CompanyModel companyModel = companyService.getCompanyModel();
req.setAttribute("companyModel", companyModel);
List<NavModel> navModelList = navService.getNavModelList();
req.setAttribute("navModelList", navModelList);
List<NewsModel> newsModelList = newsService.getNewsModelList();
req.setAttribute("newsModelList", newsModelList);
List<ProductModel> productModelList = productService.getProductModelList();
req.setAttribute("productModelList", productModelList);
List<ProductTypeModel> productTypeModelList = productTypeService.getProductTypeModelList();
req.setAttribute("productTypeModelList", productTypeModelList);
req.getRequestDispatcher("/jsp/home.jsp").forward(req,resp);
- 创建service,实现对数据进行逻辑处理
CompanyService.java
public class CompanyService {
public CompanyModel getCompanyModel() {
return CompanyDao.companyModel;
}
}
- 创建对象Dao文件,进行数据持久化存储
MessageDao.java
public class MessageDao {
public static List<MessageModel> list = new ArrayList<>();
}