mac下使用eclipse+tomcat+mysql开发 j2ee(二)

①开始运行第一个.jsp

(1)打开eclipse;

(2)点击菜单Eclipse->偏好设置->Server->Runtime Environments

(3)点击Add。。。注意路径设置是否正确,创建生成tomcat环境。

mac下使用eclipse+tomcat+mysql开发 j2ee(二)_第1张图片

4)创建项目

菜单选择File-》New-》Project-》Web-》Dynamic Web Project

输入Project Name,选择Target Runtime,finish。

在WebContent下new一个index.jsp, 修改如下:

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>





<% int intLocal_Vals; int intLocal_Amount; if(request.getParameter("Vals") != null && request.getParameter("Amount") != null) { intLocal_Vals = Integer.parseInt(request.getParameter("Vals")); intLocal_Amount = Integer.parseInt(request.getParameter("Amount")); intLocal_Vals=intLocal_Vals>>intLocal_Amount; out.print("
位移后的值为:" +intLocal_Vals); } else { out.print("位移值或位移量不能为空!"); } %>
在运行这前,先把之前的 tomcat关闭了,cd 你的 tomcat路径/bin -->sh shutdown.sh
运行效果:

mac下使用eclipse+tomcat+mysql开发 j2ee(二)_第2张图片

②第一个servlet

在项目src里面创建一个servlet,

名字命名为HelloServlet,在doGet添加Writer,运行,完成helloworld

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().write("Hello, world!");
	}

参考资料:
mac下server开发环境配置




你可能感兴趣的:(j2ee&JDBC)