D1_创建Web project

本文详细介绍Web工程的创建步骤,包括注意事项、过滤器(filter)的使用、JSP页面示例及后续实践任务,如数据库连接池、前后端分离、分页操作等,为读者提供全面的Web开发指导。

 

1 创建一个web工程

1.1 注意

  1. 每次要导入一个包或文件最好再重新创一个项目,因为导入的东西很可能出问题(Web工程以后需导入各种包),为了快速定位问题,最好一步一步测试,保证前续工作没问题!
  2. 前续工作不要省略,特别是一些需要手动导入的代码,比如 Classforname()!
  3. 调试的时候,要一步一步地区调,关注caused by.

1.2 filter

如果不用filter,则在每条Servlet前面要加上 “ request.setCharacterEncoding("utf-8"); ”

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>n_2_ServletFirst_0314</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
    <filter>
	<filter-name>CharacterEncodingFilter</filter-name>
	<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter
        </filter-class>
    <!-- 配置,参数设置 -->
	<init-param>
	<param-name>encoding</param-name>
	<param-value>utf-8</param-value>
	</init-param>
    </filter>
	
    <filter-mapping>
	<filter-name>CharacterEncodingFilter</filter-name>
	<url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

1.3 JSP 

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Spring</title>
</head>
<body>
	<h1>Winter has gone,spring is coming!</h1>
	<a href="Semester_add.jsp">新增</a>|
	<a href="Semester_delete.jsp">删除</a>|
	<a href="Semester_update.jsp">更新</a>|
	<a href="Semester_find.jsp">查找</a>
	
	<table border="6">
		<caption>SemestersList</caption>
		<tr>
			<th><input type="checkbox" id="select" /></th>
			<th>id</th>
			<th>name</th>
			<th>operation</th>
		</tr>
		<c:forEach items="${semesters}" var="semester">
			<tr>
				<td><input type="checkbox" name="soption"
					value="${semester.id }" /></td>
				<td>${semester.id}</td>
				<td>${semester.name}</td>
			</tr>
		</c:forEach>
	</table>

</body>
</html>

2 后续任务

Tasks

  • 以完成课程管理系统为导向,进行后续实践!
    • 再梳理一下JDBC,数据库连接池
    • JSP,session,request,重新理解一下前后端分离
      • filter,应用filter进行访问控制
      • 分页操作,页面需进行设计
      • 尝试实现文件上传
      • 客户端应用ckeditor等在线编辑器实现图文编辑
      • 前后端分离:将结果转换成json格式数据,客户端通过Ajax请求。
  • 正则表达式,加密,编码
  • Spring 框架

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值