首先要理清楚代碼結(jié)構(gòu)和業(yè)務(wù)結(jié)構(gòu)(應(yīng)該有些文檔或者大的流程圖),這是閱讀具體代碼的前提。
為額濟(jì)納等地區(qū)用戶(hù)提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及額濟(jì)納網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、額濟(jì)納網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專(zhuān)業(yè)、用心的態(tài)度為用戶(hù)提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶(hù)的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
閱讀Java?web項(xiàng)目的代碼:
你需要找到
View層的代碼:前端頁(yè)面、圖片、資源文件都在其中。
Controller層的代碼:控制試圖與模型層以及數(shù)據(jù)傳遞。
Service層的代碼:業(yè)務(wù)邏輯。
Dao層的代碼:數(shù)據(jù)庫(kù)訪(fǎng)問(wèn)邏輯。
從web.xml?-?appcontext.xml?-?xxx
package test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpTest {
private String u;
private String encoding;
public static void main(String[] args) throws Exception {
HttpTest client = new HttpTest("", "UTF-8");
client.run();
}
public HttpTest(String u, String encoding) {
this.u = u;
this.encoding = encoding;
}
public void run() throws Exception {
URL url = new URL(u);// 根據(jù)鏈接(字符串格式),生成一個(gè)URL對(duì)象
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();// 打開(kāi)URL
BufferedReader reader = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream(), encoding));// 得到輸入流,即獲得了網(wǎng)頁(yè)的內(nèi)容
String line; // 讀取輸入流的數(shù)據(jù),并顯示
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}
根據(jù)具體問(wèn)題類(lèi)型,進(jìn)行步驟拆解/原因原理分析/內(nèi)容拓展等。
具體步驟如下:/導(dǎo)致這種情況的原因主要是……
/**
*?@description:?
*?@author?chenshiqiang?E-mail:csqwyyx@163.com
*?@date?2014年9月7日?下午2:51:50???
*?@version?1.0???
*/
package?com.example.baidumap;
import?java.util.ArrayList;
import?java.util.Collections;
import?java.util.HashSet;
import?java.util.List;
import?android.app.Activity;
import?android.os.Bundle;
import?android.support.v4.view.PagerAdapter;
import?android.support.v4.view.PagerTabStrip;
import?android.support.v4.view.ViewPager;
import?android.text.Editable;
import?android.util.Log;
import?android.view.LayoutInflater;
import?android.view.View;
import?android.view.ViewGroup;
import?android.widget.ExpandableListView;
import?android.widget.ListView;
import?com.baidu.mapapi.map.offline.MKOLSearchRecord;
import?com.baidu.mapapi.map.offline.MKOLUpdateElement;
import?com.baidu.mapapi.map.offline.MKOfflineMap;
import?com.baidu.mapapi.map.offline.MKOfflineMapListener;
import?com.example.baidumap.adapters.OfflineExpandableListAdapter;
import?com.example.baidumap.adapters.OfflineMapAdapter;
import?com.example.baidumap.adapters.OfflineMapManagerAdapter;
import?com.example.baidumap.interfaces.OnOfflineItemStatusChangeListener;
import?com.example.baidumap.models.OfflineMapItem;
import?com.example.baidumap.utils.CsqBackgroundTask;
import?com.example.baidumap.utils.ToastUtil;
import?com.example.system.R;
public?class?BaiduOfflineMapActivity?extends?Activity?implements?MKOfflineMapListener,?OnOfflineItemStatusChangeListener
{
//?------------------------?Constants?------------------------
//?-------------------------?Fields?--------------------------
private?ViewPager?viewpager;
private?PagerTabStrip?pagertab;
private?MySearchView?svDown;
private?ListView?lvDown;
private?MySearchView?svAll;
private?ExpandableListView?lvWholeCountry;
private?ListView?lvSearchResult;
private?ListView?views?=?new?ArrayListView(2);
private?ListString?titles?=?new?ArrayListString(2);
private?MKOfflineMap?mOffline?=?null;
private?OfflineMapManagerAdapter?downAdapter;
private?OfflineMapAdapter?allSearchAdapter;
private?OfflineExpandableListAdapter?allCountryAdapter;
private?ListOfflineMapItem?itemsDown;?//?下載或下載中城市
private?ListOfflineMapItem?itemsAll;?//?所有城市,與熱門(mén)城市及下載管理對(duì)象相同
private?ListOfflineMapItem?itemsProvince;
private?ListListOfflineMapItem?itemsProvinceCity;
//?-----------------------?Constructors?----------------------
//?--------?Methods?for/from?SuperClass/Interfaces?-----------
@Override
protected?void?onCreate(Bundle?savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_offline_map);
// final?String?packname?=?this.getPackageName();
// PackageInfo?packageInfo;
// try
// {
// packageInfo?=?this.getPackageManager().getPackageInfo(packname,?PackageManager.GET_SIGNATURES);
//
//
// if?(code?==?-00)
// {
//?初始化離線(xiàn)地圖管理
mOffline?=?new?MKOfflineMap();
mOffline.init(this);
initViews();
viewpager.setCurrentItem(1);
// }
// }
// catch?(NameNotFoundException?e)
// {
// e.printStackTrace();
// }
}
private?boolean?isResumed?=?false;
@Override
protected?void?onResume()
{
super.onResume();
if?(!isResumed)
{
isResumed?=?true;
loadData();
}
}
@Override
protected?void?onDestroy()
{
super.onDestroy();
mOffline.destroy();
}
/**
?*?
?*?@author?chenshiqiang?E-mail:csqwyyx@163.com
?*?@param?type
?*????????????事件類(lèi)型:?MKOfflineMap.TYPE_NEW_OFFLINE,?MKOfflineMap.TYPE_DOWNLOAD_UPDATE,?MKOfflineMap.TYPE_VER_UPDATE.
?*?@param?state
?*????????????事件狀態(tài):?當(dāng)type為T(mén)YPE_NEW_OFFLINE時(shí),表示新安裝的離線(xiàn)地圖數(shù)目.?當(dāng)type為T(mén)YPE_DOWNLOAD_UPDATE時(shí),表示更新的城市ID.
?*/
@Override
public?void?onGetOfflineMapState(int?type,?int?state)
{
switch?(type)
{
case?MKOfflineMap.TYPE_DOWNLOAD_UPDATE:
MKOLUpdateElement?update?=?mOffline.getUpdateInfo(state);
if?(setElement(update,?true)?!=?null)
{
if?(itemsDown?!=?null??itemsDown.size()??1)
{
Collections.sort(itemsDown);
}
refreshDownList();
}
else
{
downAdapter.notifyDataSetChanged();
}
allSearchAdapter.notifyDataSetChanged();
allCountryAdapter.notifyDataSetChanged();
break;
case?MKOfflineMap.TYPE_NEW_OFFLINE:
//?有新離線(xiàn)地圖安裝
Log.d("OfflineDemo",?String.format("add?offlinemap?num:%d",?state));
break;
case?MKOfflineMap.TYPE_VER_UPDATE:
//?版本更新提示
break;
}
}
/**
?*?百度下載狀態(tài)改變(暫停--》恢復(fù))居然不回調(diào),所以改變狀態(tài)時(shí)自己得增加接口監(jiān)聽(tīng)狀態(tài)改變刷新界面
?*?
?*?@author?chenshiqiang?E-mail:csqwyyx@163.com
?*?@param?item
?*????????????有狀態(tài)改變的item
?*?@param?removed
?*????????????item是否被刪除
?*/
@Override
public?void?statusChanged(OfflineMapItem?item,?boolean?removed)
{
if?(removed)
{
for?(int?i?=?itemsDown.size()?-?1;?i?=?0;?i--)
{
OfflineMapItem?temp?=?itemsDown.get(i);
if?(temp.getCityId()?==?item.getCityId())
{
itemsDown.remove(i);
}
}
refreshDownList();
}
else
{
loadData();
downAdapter.notifyDataSetChanged();
}
allSearchAdapter.notifyDataSetChanged();
allCountryAdapter.notifyDataSetChanged();
}
//?---------------------?Methods?public?----------------------
public?void?toDownloadPage()
{
viewpager.setCurrentItem(0);
}
//?---------------------?Methods?private?---------------------
private?void?initViews()
{
//?TODO
viewpager?=?(ViewPager)?findViewById(R.id.viewpager);
pagertab?=?(PagerTabStrip)?findViewById(R.id.pagertab);
LayoutInflater?inf?=?LayoutInflater.from(this);
View?v1?=?inf.inflate(R.layout.view_offline_download,?null,?false);
svDown?=?(MySearchView)?v1.findViewById(R.id.svDown);
lvDown?=?(ListView)?v1.findViewById(R.id.lvDown);
views.add(v1);
View?v2?=?inf.inflate(R.layout.view_offline_countrys,?null,?false);
svAll?=?(MySearchView)?v2.findViewById(R.id.svAll);
lvWholeCountry?=?(ExpandableListView)?v2.findViewById(R.id.lvWholeCountry);
lvSearchResult?=?(ListView)?v2.findViewById(R.id.lvSearchResult);
views.add(v2);
titles.add("下載管理");
titles.add("城市列表");
pagertab.setTabIndicatorColor(0xff00cccc);
pagertab.setDrawFullUnderline(false);
pagertab.setBackgroundColor(0xFF38B0DE);
pagertab.setTextSpacing(50);
viewpager.setOffscreenPageLimit(2);
viewpager.setAdapter(new?MyPagerAdapter());
svDown.setSearchListener(new?MySearchView.SearchListener()
{
@Override
public?void?afterTextChanged(Editable?text)
{
refreshDownList();
}
@Override
public?void?search(String?text)
{
}
});
svAll.setSearchListener(new?MySearchView.SearchListener()
{
@Override
public?void?afterTextChanged(Editable?text)
{
refreshAllSearchList();
}
@Override
public?void?search(String?text)
{
}
});
downAdapter?=?new?OfflineMapManagerAdapter(this,?mOffline,?this);
lvDown.setAdapter(downAdapter);
allSearchAdapter?=?new?OfflineMapAdapter(this,?mOffline,?this);
lvSearchResult.setAdapter(allSearchAdapter);
allCountryAdapter?=?new?OfflineExpandableListAdapter(this,?mOffline,?this);
lvWholeCountry.setAdapter(allCountryAdapter);
lvWholeCountry.setGroupIndicator(null);
}
/**
?*?刷新下載列表,?根據(jù)搜索關(guān)鍵字及itemsDown?下載管理數(shù)量變動(dòng)時(shí)調(diào)用
?*/
private?void?refreshDownList()
{
String?key?=?svDown.getInputText();
if?(key?==?null?||?key.length()??1)
{
downAdapter.setDatas(itemsDown);
}
else
{
ListOfflineMapItem?filterList?=?new?ArrayListOfflineMapItem();
if?(itemsDown?!=?null??!itemsDown.isEmpty())
{
for?(OfflineMapItem?i?:?itemsDown)
{
if?(i.getCityName().contains(key))
{
filterList.add(i);
}
}
}
downAdapter.setDatas(filterList);
}
}
/**
?*?刷新所有城市搜索結(jié)果
?*/
private?void?refreshAllSearchList()
{
String?key?=?svAll.getInputText();
if?(key?==?null?||?key.length()??1)
{
lvSearchResult.setVisibility(View.GONE);
lvWholeCountry.setVisibility(View.VISIBLE);
allSearchAdapter.setDatas(null);
}
else
{
lvSearchResult.setVisibility(View.VISIBLE);
lvWholeCountry.setVisibility(View.GONE);
ListOfflineMapItem?filterList?=?new?ArrayListOfflineMapItem();
if?(itemsAll?!=?null??!itemsAll.isEmpty())
{
for?(OfflineMapItem?i?:?itemsAll)
{
if?(i.getCityName().contains(key))
{
filterList.add(i);
}
}
}
allSearchAdapter.setDatas(filterList);
}
}
private?void?loadData()
{
new?CsqBackgroundTaskVoid(this)
{
@Override
protected?Void?onRun()
{
//?TODO?Auto-generated?method?stub
//?導(dǎo)入離線(xiàn)地圖包
//?將從官網(wǎng)下載的離線(xiàn)包解壓,把vmp文件夾拷入SD卡根目錄下的BaiduMapSdk文件夾內(nèi)。
//?把網(wǎng)站上下載的文件解壓,將\BaiduMap\vmp\l里面的.dat_svc文件,拷貝到手機(jī)BaiduMapSDK/vmp/h目錄下
int?num?=?mOffline.importOfflineData();
if?(num??0)
{
ToastUtil.showToastInfo(BaiduOfflineMapActivity.this,?"成功導(dǎo)入"?+?num?+?"個(gè)離線(xiàn)包",?false);
}
ListMKOLSearchRecord?all?=?null;
try
{
all?=?mOffline.getOfflineCityList();
}
catch?(Exception?e)
{
e.printStackTrace();
}
if?(all?==?null?||?all.isEmpty())
{
ToastUtil.showToastInfo(BaiduOfflineMapActivity.this,?"未獲取到離線(xiàn)地圖城市數(shù)據(jù),可能有其他應(yīng)用正在使用百度離線(xiàn)地圖功能!",?false);
return?null;
}
ListMKOLSearchRecord?hotCity?=?mOffline.getHotCityList();
HashSetInteger?hotCityIds?=?new?HashSetInteger();
if?(!hotCity.isEmpty())
{
for?(MKOLSearchRecord?r?:?hotCity)
{
hotCityIds.add(r.cityID);
}
}
itemsAll?=?new?ArrayListOfflineMapItem();
itemsDown?=?new?ArrayListOfflineMapItem();
itemsProvince?=?new?ArrayListOfflineMapItem();
itemsProvinceCity?=?new?ArrayListListOfflineMapItem();
//?cityType?0:全國(guó);1:省份;2:城市,如果是省份,可以通過(guò)childCities得到子城市列表
//?全國(guó)概略圖、直轄市、港澳?子城市列表
ArrayListMKOLSearchRecord?childMunicipalities?=?new?ArrayListMKOLSearchRecord();
proHot.cityName?=?"熱門(mén)城市";
proHot.childCities?=?cs;
ListMKOLUpdateElement?updates?=?mOffline.getAllUpdateInfo();
if?(updates?!=?null??updates.size()??0)
{
}
@Override
protected?void?onResult(Void?result)
{
//?TODO?Auto-generated?method?stub
refreshDownList();
refreshAllSearchList();
allCountryAdapter.setDatas(itemsProvince,?itemsProvinceCity);
}
}.execute();
}
.java文件的話(huà),非項(xiàng)目那種單篇幅的源代碼需要先進(jìn)行編譯,生成.class文件可以在命令控制臺(tái)下用java 文件名 進(jìn)行運(yùn)行,編譯java文件需要javac.exe程序 應(yīng)該是jdk中的工具,所以你需要下載jdk并配置環(huán)境變量,然后在控制臺(tái)運(yùn)行javac編譯源文件所在目錄下的java文件,會(huì)在本目錄下生成一個(gè)同名的.class文件
(沒(méi)有報(bào)錯(cuò)的情況下) ,然后運(yùn)行java 文件名 即可運(yùn)行該代碼(前提是你這篇文件需要有main方法)。
首先 java網(wǎng)站是基于jdk運(yùn)行的。你得先裝jdk。去官網(wǎng)下載一個(gè)jdk安裝。然后你得編譯你的項(xiàng)目,打包到容器(tomcat,weblogic,jboss等)中運(yùn)行即可。再提醒一下就是,看看你的源代碼有木有用到數(shù)據(jù)庫(kù)或者其他類(lèi)型的服務(wù)。如果有的話(huà),你得裝數(shù)據(jù)庫(kù)或服務(wù),并且初始化數(shù)據(jù)。再啟動(dòng)你的你的容器。