Eclipse开发web项目

在Eclipese中添加Tomcat

window
preferences
server
Runtime Environment

进行Add Tomcat服务器,记得在server窗口中也要添加一下

新建web项目

  1. new 新建Dynamic Web project
  2. 在webcontent下面创建index.jsp
  3. 在浏览器中输入http://localhost:8080/Mystudy/index.jsp 进行访问项目
    WEB-INF无法通过浏览器直接访问,只能通过请求转发来访问

修改Eclipse中Tomcat的地址

Eclipse开发web项目

在Eclipse中编辑html文件实时预览

右键单击html文件 选择open with web page editor

页面中form表单的action填写如下

Eclipse开发web项目

编码问题

设置requset编码
request.setCharacterEncoding("utf-8");
或者
String name = new String(request.getParameter("username").getBytes("ISO8859-1"),"utf-8");

设置response编码
response.setContentType("text/html;charset=utf-8");

JDBC连接Mysql数据库