Java獲得此次要求URL和辦事器根途徑的辦法。本站提示廣大學習愛好者:(Java獲得此次要求URL和辦事器根途徑的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是Java獲得此次要求URL和辦事器根途徑的辦法正文
本文引見了Java獲得此次要求URL和獲得辦事器根途徑的辦法,而且停止舉例解釋,感興致的同伙可以進修自創下文的內容。
1、 獲得此次要求的URL
String requestUrl = request.getScheme() //以後鏈接應用的協定
+"://" + request.getServerName()//辦事器地址
+ ":" + request.getServerPort() //端標語
+ request.getContextPath() //運用稱號,假如運用稱號為
+ request.getServletPath() //要求的絕對url
+ "?" + request.getQueryString(); //要求參數
舉例:
http://127.0.0.1:8080/world/index.jsp?name=lilei&sex=1 <Context path="world" docBase="/home/webapps" debug="0" reloadable="true"/> request.getScheme() = "http"; request.getServerName() = "127.0.0.1"; request.getServerPort() = "8080"; request.getContextPath() = "world"; request.getServletPath() = "index.jsp"; request.getQueryString() = "name=lilei&sex=1"; http://127.0.0.1:8080/world/index.jsp?name=lilei&sex=1 <Context path="" docBase="/home/webapps" debug="0" reloadable="true"/> request.getScheme() = "http"; request.getServerName() = "127.0.0.1"; request.getServerPort() = "8080"; request.getContextPath() = ""; request.getServletPath() = "world/index.jsp"; request.getQueryString() = "name=lilei&sex=1";
2、獲得辦事器根途徑
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
應用以下:
<head> <link rel="stylesheet" type="text/css" href="<%=basePath%>static/css/framework/themes/default/easyui.css"> <link rel="stylesheet" type="text/css" href="<%=basePath%>static/css/framework/themes/icon.css"> <link rel="stylesheet" type="text/css" href="<%=basePath%>static/css/base.css"> <script src="<%=basePath%>static/javascript/framework/jquery.min.js"></script> <script src="<%=basePath%>static/javascript/framework/jquery.easyui.min.js"></script> <script src="<%=basePath%>static/javascript/framework/easyui-lang-zh_CN.js"></script> <script src="<%=basePath%>static/javascript/framework/easyui-util.js"></script> </head>
以上就是Java獲得此次要求URL和辦事器根途徑的辦法,願望對年夜家的進修有所贊助。
��起首依據進度條的寬度和以後進度、總進度算出以後的地位:
//mProgressWidth為進度條的寬度,依據以後進度算出進度條的地位 mCurrentProgressPosition = mProgressWidth * mProgress / TOTAL_PROGRESS;
然後依照下面的邏輯停止繪制,個中須要盤算上圖中的白色弧角角度,盤算辦法以下:
// 單邊角度 int angle = (int) Math.toDegrees(Math.acos((mArcRadius - mCurrentProgressPosition)/ (float) mArcRadius));
Math.acos() -反余弦函數;
Math.toDegrees() - 弧度轉化為角度,Math.toRadians 角度轉化為弧度
所以圓弧的肇端點為:
int startAngle = 180 - angle;
圓弧劃過的角度為:
2 * angle
這一塊的代碼以下:
// mProgressWidth為進度條的寬度,依據以後進度算出進��條的地位
mCurrentProgressPosition = mProgressWidth * mProgress / TOTAL_PROGRESS;
// 即以後地位在圖中所示1規模內
if (mCurrentProgressPosition < mArcRadius) {
Log.i(TAG, "mProgress = " + mProgress + "---mCurrentProgressPosition = "
+ mCurrentProgressPosition
+ "--mArcProgressWidth" + mArcRadius);
// 1.繪制白色ARC,繪制orange ARC
// 2.繪制白色矩形
// 1.繪制白色ARC
canvas.drawArc(mArcRectF, 90, 180, false, mWhitePaint);
// 2.繪制白色矩形
mWhiteRectF.left = mArcRightLocation;
canvas.drawRect(mWhiteRectF, mWhitePaint);
// 3.繪制棕色 ARC
// 單邊角度
int angle = (int) Math.toDegrees(Math.acos((mArcRadius - mCurrentProgressPosition)
/ (float) mArcRadius));
// 肇端的地位
int startAngle = 180 - angle;
// 掃過的角度
int sweepAngle = 2 * angle;
Log.i(TAG, "startAngle = " + startAngle);
canvas.drawArc(mArcRectF, startAngle, sweepAngle, false, mOrangePaint);
} else {
Log.i(TAG, "mProgress = " + mProgress + "---transfer-----mCurrentProgressPosition = "
+ mCurrentProgressPosition
+ "--mArcProgressWidth" + mArcRadius);
// 1.繪制white RECT
// 2.繪制Orange ARC
// 3.繪制orange RECT
// 1.繪制white RECT
mWhiteRectF.left = mCurrentProgressPosition;
canvas.drawRect(mWhiteRectF, mWhitePaint);
// 2.繪制Orange ARC
canvas.drawArc(mArcRectF, 90, 180, false, mOrangePaint);
// 3.繪制orange RECT
mOrangeRectF.left = mArcRightLocation;
mOrangeRectF.right = mCurrentProgressPosition;
canvas.drawRect(mOrangeRectF, mOrangePaint);
}
接上去再來看葉子部門:
起首依據後果情形根本肯定出 曲線函數,尺度函數方程為:y = A(wx+Q)+h,個中w影響周期,A影響振幅 ,周期T= 2 * Math.PI/w;
依據後果可以看出,周期年夜致為總進度長度,所以肯定w=(float) ((float) 2 * Math.PI /mProgressWidth);
細心不雅察後果,我們可以發明,葉���飛舞的進程中振幅不是完整分歧的,發生一種參差的後果,既然如斯,我們給葉子界說一個Type,依據Type 肯定分歧的振幅;
我們創立一個葉子對象:
private class Leaf {
// 在繪制部門的地位
float x, y;
// 掌握葉子飛舞的幅度
StartType type;
// 扭轉角度
int rotateAngle;
// 扭轉偏向--0代表順時針,1代表逆時針
int rotateDirection;
// 肇端時光(ms)
long startTime;
}
類型采取列舉停止界說,其實就是用來辨別分歧的振幅:
private enum StartType {
LITTLE, MIDDLE, BIG
}
創立一個LeafFactory類用於創立一個或多個葉子信息:
private class LeafFactory {
private static final int MAX_LEAFS = 6;
Random random = new Random();
// 生成一個葉子信息
public Leaf generateLeaf() {
Leaf leaf = new Leaf();
int randomType = random.nextInt(3);
// 隨時類型- 隨機振幅
StartType type = StartType.MIDDLE;
switch (randomType) {
case 0:
break;
case 1:
type = StartType.LITTLE;
break;
case 2:
type = StartType.BIG;
break;
default:
break;
}
leaf.type = type;
// 隨機肇端的扭轉角度
leaf.rotateAngle = random.nextInt(360);
// 隨機扭轉偏向(順時針或逆時針)
leaf.rotateDirection = random.nextInt(2);
// 為了發生交織的感到,閃開始的時光有必定的隨機性
mAddTime += random.nextInt((int) (LEAF_FLOAT_TIME * 1.5));
leaf.startTime = System.currentTimeMillis() + mAddTime;
return leaf;
}
// 依據最年夜葉子數發生葉子信息
public List<Leaf> generateLeafs() {
return generateLeafs(MAX_LEAFS);
}
// 依據傳入的葉子數目發生葉子信息
public List<Leaf> generateLeafs(int leafSize) {
List<Leaf> leafs = new LinkedList<Leaf>();
for (int i = 0; i < leafSize; i++) {
leafs.add(generateLeaf());
}
return leafs;
}
}
界說兩個常亮分離記載中等振幅和之間的振幅差:
// 中等振幅年夜小 private static final int MIDDLE_AMPLITUDE = 13; // 分歧類型之間的振幅差距 private static final int AMPLITUDE_DISPARITY = 5; [html] view plain copy 在CODE上檢查代碼片派生到我的代碼片 // 中等振幅年夜小 private int mMiddleAmplitude = MIDDLE_AMPLITUDE; // 振幅差 private int mAmplitudeDisparity = AMPLITUDE_DISPARITY;
有了以上信息,我們則可以獲得到葉子的Y值:
// 經由過程葉子信息獲得以後葉子的Y值
private int getLocationY(Leaf leaf) {
// y = A(wx+Q)+h
float w = (float) ((float) 2 * Math.PI / mProgressWidth);
float a = mMiddleAmplitude;
switch (leaf.type) {
case LITTLE:
// 小振幅 = 中等振幅 - 振幅差
a = mMiddleAmplitude - mAmplitudeDisparity;
break;
case MIDDLE:
a = mMiddleAmplitude;
break;
case BIG:
// 小振幅 = 中等振幅 + 振幅差
a = mMiddleAmplitude + mAmplitudeDisparity;
break;
default:
break;
}
Log.i(TAG, "---a = " + a + "---w = " + w + "--leaf.x = " + leaf.x);
return (int) (a * Math.sin(w * leaf.x)) + mArcRadius * 2 / 3;
}
接上去,我們開端繪制葉子:
/**
* 繪制葉子
*
* @param canvas
*/
private void drawLeafs(Canvas canvas) {
long currentTime = System.currentTimeMillis();
for (int i = 0; i < mLeafInfos.size(); i++) {
Leaf leaf = mLeafInfos.get(i);
if (currentTime > leaf.startTime && leaf.startTime != 0) {
// 繪制葉子--依據葉子的類型和以後時光得出葉子的(x,y)
getLeafLocation(leaf, currentTime);
// 依據時光盤算扭轉角度
canvas.save();
// 經由過程Matrix掌握葉子扭轉
Matrix matrix = new Matrix();
float transX = mLeftMargin + leaf.x;
float transY = mLeftMargin + leaf.y;
Log.i(TAG, "left.x = " + leaf.x + "--leaf.y=" + leaf.y);
matrix.postTranslate(transX, transY);
// 經由過程時光聯系關系扭轉角度,則可以直接經由過程修正LEAF_ROTATE_TIME調理葉子扭轉快慢
float rotateFraction = ((currentTime - leaf.startTime) % LEAF_ROTATE_TIME)
/ (float) LEAF_ROTATE_TIME;
int angle = (int) (rotateFraction * 360);
// 依據葉子扭轉偏向肯定葉子扭轉角度
int rotate = leaf.rotateDirection == 0 ? angle + leaf.rotateAngle : -angle
+ leaf.rotateAngle;
matrix.postRotate(rotate, transX
+ mLeafWidth / 2, transY + mLeafHeight / 2);
canvas.drawBitmap(mLeafBitmap, matrix, mBitmapPaint);
canvas.restore();
} else {
continue;
}
}
}
最初,向外層裸露幾個接口:
/**
* 設置中等振幅
*
* @param amplitude
*/
public void setMiddleAmplitude(int amplitude) {
this.mMiddleAmplitude = amplitude;
}
/**
* 設置振幅差
*
* @param disparity
*/
public void setMplitudeDisparity(int disparity) {
this.mAmplitudeDisparity = disparity;
}
/**
* 獲得中等振幅
*
* @param amplitude
*/
public int getMiddleAmplitude() {
return mMiddleAmplitude;
}
/**
* 獲得振幅差
*
* @param disparity
*/
public int getMplitudeDisparity() {
return mAmplitudeDisparity;
}
/**
* 設置進度
*
* @param progress
*/
public void setProgress(int progress) {
this.mProgress = progress;
postInvalidate();
}
/**
* 設置葉子飄完一個周期所花的時光
*
* @param time
*/
public void setLeafFloatTime(long time) {
this.mLeafFloatTime = time;
}
/**
* 設置葉子扭轉一周所花的時光
*
* @param time
*/
public void setLeafRotateTime(long time) {
this.mLeafRotateTime = time;
這些接口用來干嗎呢?用於把我們的動效做成完整可手動調理的,如許做有甚麼利益呢?
1. 加倍便於產物、射雞濕檢查後果,防止YY,本身手動調理,不會湧現要你一遍遍的改參數裝置、檢查、再改、再檢查... ... N遍以後說 “這似乎不是我想要的” -- 剎時天崩地裂,昏天黑地,感到被全球擯棄;
2. 便於表現你是一個斟酌周全,思想周密,會編程、會設計的藝術家,固然這純屬YY,重要照樣便利年夜家;
如斯一來,射雞濕們只須要赓續的調理便可及時的看到展示的後果,最初只須要把終究的參數反應過去便可,萬事年夜吉,依然如故;
固然,假如對方是個英俊的妹子,而你又苦於沒無機會搭赸,以上內容就當我沒說,縱情的不按請求寫吧,她確定會自動找你的,說不定連飯都反過去請了... ...
好啦,言歸正傳,完成掃尾部門,我們讓一切的參數都可調理起來:
把剩下的layout 和activity貼出來:
activity:
public class LeafLoadingActivity extends Activity implements OnSeekBarChangeListener,
OnClickListener {
Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case REFRESH_PROGRESS:
if (mProgress < 40) {
mProgress += 1;
// 隨機800ms之內刷新一次
mHandler.sendEmptyMessageDelayed(REFRESH_PROGRESS,
new Random().nextInt(800));
mLeafLoadingView.setProgress(mProgress);
} else {
mProgress += 1;
// 隨機1200ms之內刷新一次
mHandler.sendEmptyMessageDelayed(REFRESH_PROGRESS,
new Random().nextInt(1200));
mLeafLoadingView.setProgress(mProgress);
}
break;
default:
break;
}
};
};
private static final int REFRESH_PROGRESS = 0x10;
private LeafLoadingView mLeafLoadingView;
private SeekBar mAmpireSeekBar;
private SeekBar mDistanceSeekBar;
private TextView mMplitudeText;
private TextView mDisparityText;
private View mFanView;
private Button mClearButton;
private int mProgress = 0;
private TextView mProgressText;
private View mAddProgress;
private SeekBar mFloatTimeSeekBar;
private SeekBar mRotateTimeSeekBar;
private TextView mFloatTimeText;
private TextView mRotateTimeText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.leaf_loading_layout);
initViews();
mHandler.sendEmptyMessageDelayed(REFRESH_PROGRESS, 3000);
}
private void initViews() {
mFanView = findViewById(R.id.fan_pic);
RotateAnimation rotateAnimation = DXAnimationUtils.initRotateAnimation(false, 1500, true,
Animation.INFINITE);
mFanView.startAnimation(rotateAnimation);
mClearButton = (Button) findViewById(R.id.clear_progress);
mClearButton.setOnClickListener(this);
mLeafLoadingView = (LeafLoadingView) findViewById(R.id.leaf_loading);
mMplitudeText = (TextView) findViewById(R.id.text_ampair);
mMplitudeText.setText(getString(R.string.current_mplitude,
mLeafLoadingView.getMiddleAmplitude()));
mDisparityText = (TextView) findViewById(R.id.text_disparity);
mDisparityText.setText(getString(R.string.current_Disparity,
mLeafLoadingView.getMplitudeDisparity()));
mAmpireSeekBar = (SeekBar) findViewById(R.id.seekBar_ampair);
mAmpireSeekBar.setOnSeekBarChangeListener(this);
mAmpireSeekBar.setProgress(mLeafLoadingView.getMiddleAmplitude());
mAmpireSeekBar.setMax(50);
mDistanceSeekBar = (SeekBar) findViewById(R.id.seekBar_distance);
mDistanceSeekBar.setOnSeekBarChangeListener(this);
mDistanceSeekBar.setProgress(mLeafLoadingView.getMplitudeDisparity());
mDistanceSeekBar.setMax(20);
mAddProgress = findViewById(R.id.add_progress);
mAddProgress.setOnClickListener(this);
mProgressText = (TextView) findViewById(R.id.text_progress);
mFloatTimeText = (TextView) findViewById(R.id.text_float_time);
mFloatTimeSeekBar = (SeekBar) findViewById(R.id.seekBar_float_time);
mFloatTimeSeekBar.setOnSeekBarChangeListener(this);
mFloatTimeSeekBar.setMax(5000);
mFloatTimeSeekBar.setProgress((int) mLeafLoadingView.getLeafFloatTime());
mFloatTimeText.setText(getResources().getString(R.string.current_float_time,
mLeafLoadingView.getLeafFloatTime()));
mRotateTimeText = (TextView) findViewById(R.id.text_rotate_time);
mRotateTimeSeekBar = (SeekBar) findViewById(R.id.seekBar_rotate_time);
mRotateTimeSeekBar.setOnSeekBarChangeListener(this);
mRotateTimeSeekBar.setMax(5000);
mRotateTimeSeekBar.setProgress((int) mLeafLoadingView.getLeafRotateTime());
mRotateTimeText.setText(getResources().getString(R.string.current_float_time,
mLeafLoadingView.getLeafRotateTime()));
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (seekBar == mAmpireSeekBar) {
mLeafLoadingView.setMiddleAmplitude(progress);
mMplitudeText.setText(getString(R.string.current_mplitude,
progress));
} else if (seekBar == mDistanceSeekBar) {
mLeafLoadingView.setMplitudeDisparity(progress);
mDisparityText.setText(getString(R.string.current_Disparity,
progress));
} else if (seekBar == mFloatTimeSeekBar) {
mLeafLoadingView.setLeafFloatTime(progress);
mFloatTimeText.setText(getResources().getString(R.string.current_float_time,
progress));
}
else if (seekBar == mRotateTimeSeekBar) {
mLeafLoadingView.setLeafRotateTime(progress);
mRotateTimeText.setText(getResources().getString(R.string.current_rotate_time,
progress));
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onClick(View v) {
if (v == mClearButton) {
mLeafLoadingView.setProgress(0);
mHandler.removeCallbacksAndMessages(null);
mProgress = 0;
} else if (v == mAddProgress) {
mProgress++;
mLeafLoadingView.setProgress(mProgress);
mProgressText.setText(String.valueOf(mProgress));
}
}
}
layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fed255"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp"
android:text="loading ..."
android:textColor="#FFA800"
android:textSize=" 30dp" />
<RelativeLayout
android:id="@+id/leaf_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp" >
<com.百度.batterysaverDemo.ui.LeafLoadingView
android:id="@+id/leaf_loading"
android:layout_width="302dp"
android:layout_height="61dp"
android:layout_centerHorizontal="true" />
<ImageView
android:id="@+id/fan_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="35dp"
android:src="@drawable/fengshan" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/seek_content_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp" >
<TextView
android:id="@+id/text_ampair"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#ffffa800"
android:textSize="15dp" />
<SeekBar
android:id="@+id/seekBar_ampair"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/text_disparity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#ffffa800"
android:textSize="15dp" />
<SeekBar
android:id="@+id/seekBar_distance"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/text_float_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#ffffa800"
android:textSize="15dp" />
<SeekBar
android:id="@+id/seekBar_float_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/text_rotate_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#ffffa800"
android:textSize="15dp" />
<SeekBar
android:id="@+id/seekBar_rotate_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1" />
</LinearLayout>
<Button
android:id="@+id/clear_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="去除進度條,玩轉弧線"
android:textSize="18dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<Button
android:id="@+id/add_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="增長進度: "
android:textSize="18dp" />
<TextView
android:id="@+id/text_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#ffffa800"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
終究後果以下,原來錄了20+s,然則PS只能轉5s,所以有興致的年夜家本身運轉的玩吧:
以上就是本文的全體內容,願望對年夜家的進修有所贊助。