特别篇_搭建eclipse服务器_141017

来源:互联网 发布:dlp数据泄露防护 编辑:程序博客网 时间:2024/04/30 02:36

事先说明,个人为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());}}@Overrideprotected 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



0 0