特别篇_搭建eclipse服务器_141017

事先说明,个人为64位电脑,安装了apache-TomCat , 以及Eclpse-EE。

这两个都是不需要安装的,直接解压就可以用了

本文最后会附带下载链接。


第一步: 打开eclipse EE  --> File --> new --> Dynamic Web Project ;

第二步:填入参数如图:

  注意: 在TargetRuntime一栏,选择 Apache Tomcat v8.0 ,会跳出一个 Tomcat Installation Directory, 请选择之前你放置 tomcat的目录


第三步: 一路next + finish 就结束了。

 

任意,写入jsp或xml或java文件,就是自己操作了

最后贴上一个自己写的代码:

  功能: 用来接受 get 和 post 请求

package com.yline.show_54;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class show_54
 */
@WebServlet("/show_54")
public class show_54 extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public show_54() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		System.out.println("username:"+username);
		System.out.println("password:"+password);
		
		if("yline江".equals(username)&&"123".equals(password)){
			response.getOutputStream().write("登陆成功".getBytes());
		}else{
			response.getOutputStream().write("登陆失败".getBytes());
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String username = new String(req.getParameter("username").getBytes("iso-8859-1"),"utf-8");
		String password = req.getParameter("password");
		
		System.out.println("username:"+username);
		System.out.println("password:"+password);
		
		if("yline江".equals(username)&&"123".equals(password)){
			resp.getOutputStream().write("登陆成功".getBytes());
		}else{
			resp.getOutputStream().write("登陆失败".getBytes());
		}
	}
}
  

jsp文件:

<%@ page language="java" contentType="text/html; charset=gb2312"
    pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
多的是你不知道的事
<br>
多的是你不知道的事
<br>
多的是你不知道的事
<br>
多的是你不知道的事
<br>
多的是你不知道的事
<br>
</body>
</html>


最后介绍一下运行:   右键 --> run as --> Run on Server

jsp文件的运行结果:



注意:在上图中的 URL地址,中的locallhost指的是自己电脑的IP,所以,在eclipse中使用的时候,要把locallhost改成自己的IP

查询电脑IP 方法:

1 输入cmd -> 进入命令行 

2 输入ipconfig

apache-tomcat-8.0.14-windows-x64 下载链接:

官网:  http://tomcat.apache.org/download-80.cgi

个人:  http://pan.baidu.com/s/1i39UQfN

eclipse EE 下载链接:

http://pan.baidu.com/s/1mgxD2U8

本文代码下载链接:

http://pan.baidu.com/s/1kTp7XER



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值