Android服務端開發1-使用Eclipse搭建Java Web服務端,androideclipse

來源:互聯網
上載者:User

Android服務端開發1-使用Eclipse搭建Java Web服務端,androideclipse

本篇部落格介紹如何使用Eclipse來建立一個Java Web程式,為後面講通過Android用戶端跟服務端進行互動打下基礎,關於服務端可以選用的程式很多,主流的搭配是Android用戶端+PHP服務端,我們也可以使用Android用戶端+Java EE服務端這樣的搭配,就看公司是以哪種方式提供了。

建立一個Java Web程式,沒有特別複雜的流程,我們先準備一下原材料:
1. Eclipse(註:這個不是ADT Bundle,最好到官網下載針對開發Java EE的IDE,如果可以的話,選中MyEclipse來進行Java EE會是更方便的選擇)
2. tomcat(這裡下載的時tomcat 7.x)
3. jdk(註:這個是必須的,不多說)

下載完成Eclipse不用安裝,可以直接雙擊開啟,tomcat如果你下的是一個壓縮包,解壓縮之後放到合適的地方即可。

下面是配置的步驟(mac下的配置,windows類似):

最後finish完成配置。

下面是建立一個Server步驟

建立好之後,需要對修改tomcat的配置

修改完畢之後,就可以啟動tomcat,在瀏覽器中訪問http://localhost:8080/

下面是建立一個Web程式

建立完成後,在WebContent目錄下建立啟動也,index.jsp

然後我們啟動tomcat,訪問我們的項目:

註:一定要由web.xml設定檔,然後在WebContent中建立相應的啟動頁,不然會提示404的錯誤。

/web/WebContent/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">  <display-name>web</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></web-app>

/web/WebContent/index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!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=UTF-8"><title>web</title></head><body>這是我們的第一個web項目</body></html>

到目前為止,已經詳細的介紹如何通過Eclipse來搭建Java Web服務端,各位自己動手試一下,如有問題,留言討論。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.