2.把资源放在webapps \Root下面
3.启动tomcat 在Bin文件夹下 startUp
如果出现一闪而过的情况,就重新配置一下java环境,在path后面加上C:\Program Files\Java\jdk1.7.0_80\bin;C:\Program \Java\jdk1.7.0_80\jre\bin
4.找到自己的ip 如何访问 http://192.168.1.自己的ip:8080/
例如:http://192.168.1.100:8080/images/1.jpg
8080为本地的端口,也就是自己电脑的端口
wv.loadUrl(path);//直接用webView加载网址就可以了
<uses-permission android:name="android.permission.INTERNET" />权限不要忘记加了
layout中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="@+id/et_path"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/iv_go"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/jiantou"
/>
<WebView
android:layout_below="@id/et_path"
android:id="@+id/wv"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
java逻辑代码
public class MainActivity extends Activity {
private EditText et_path;
private ImageView iv_go;
private WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_path = (EditText) findViewById(R.id.et_path);
iv_go = (ImageView) findViewById(R.id.iv_go);
wv = (WebView) findViewById(R.id.wv);
iv_go.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String path=et_path.getText().toString().trim();
wv.loadUrl(path);
}});
}
}