java SWT浏览器无法显示html5本地存储 浏览器html文件

基于eclipse swt做java浏览器内嵌等功能 - wangzi6hao - ITeye技术网站
博客分类:
swt-3.5M4-win32-win32-x86.zip 包下载地址:
http://download.csdn.net/source/921856
csdn上有些朋友说我这个是骗人的包。我无语。几个dome,你们自己去看吧。别不会用就说我人品有问题。
import java.util.ArrayL
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.B
import org.eclipse.swt.browser.OpenWindowL
import org.eclipse.swt.browser.VisibilityWindowL
import org.eclipse.swt.browser.WindowE
import org.eclipse.swt.events.DisposeE
import org.eclipse.swt.events.DisposeL
import org.eclipse.swt.graphics.I
import org.eclipse.swt.graphics.P
import org.eclipse.swt.layout.FillL
import org.eclipse.swt.widgets.D
import org.eclipse.swt.widgets.E
import org.eclipse.swt.widgets.L
import org.eclipse.swt.widgets.S
public class BrowserTest1 {
static final ArrayList urls = new ArrayList(); // @jve:decl-index=0:
static boolean canRemove =
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("jog36行业招聘");
Image image = new Image(shell.getDisplay(), "Favicon.ico");
shell.setImage(image);
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
initialize(display, browser);
shell.open();
browser.setUrl("");
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
display.dispose();
static void initialize(final Display display, Browser browser) {
browser.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
System.out.println("event.time:" + event.time);
browser.addOpenWindowListener(new OpenWindowListener() {
public void open(WindowEvent event) {
// Embed the new window
final Shell shell = new Shell(display);
shell.setText("New Window");
shell.setLayout(new FillLayout());
final Browser browser = new Browser(shell, SWT.NONE);
initialize(display, browser);
event.browser =
event.display.asyncExec(new Runnable() {
public void run() {
String url = browser.getUrl();
System.out.println(url);
System.out.println(browser.getText());
if (urls.contains(url)){
//flag to chek if the window is closed automatic
canRemove =
shell.close();
canRemove =
urls.add(url);
browser.addVisibilityWindowListener(new VisibilityWindowListener() {
public void hide(WindowEvent event) {
Browser browser = (Browser) event.
Shell shell = browser.getShell();
shell.setVisible(false);
public void show(WindowEvent event) {
Browser browser = (Browser) event.
Shell shell = browser.getShell();
if (event.location != null)
shell.setLocation(event.location);
if (event.size != null) {
Point size = event.
shell.puteSize(size.x, size.y));
if (event.addressBar || event.menuBar || event.statusBar
|| event.toolBar) {
// Create widgets for the address bar, menu bar, status bar and/or tool bar
// leave enough space in the Shell to accomodate a Browser of the size
// given by event.size
shell.open();
browser.addDisposeListener(new DisposeListener(){
public void widgetDisposed(DisposeEvent event){
Browser browser = (Browser) event.
if (canRemove)
urls.remove(browser.getUrl());
Shell shell = browser.getShell();
// shell.close();
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.B
import org.eclipse.swt.browser.CloseWindowL
import org.eclipse.swt.browser.LocationE
import org.eclipse.swt.browser.LocationL
import org.eclipse.swt.browser.OpenWindowL
import org.eclipse.swt.browser.ProgressE
import org.eclipse.swt.browser.ProgressL
import org.eclipse.swt.browser.StatusTextE
import org.eclipse.swt.browser.StatusTextL
import org.eclipse.swt.browser.WindowE
import org.eclipse.swt.events.SelectionA
import org.eclipse.swt.events.SelectionE
import org.eclipse.swt.layout.FormA
import org.eclipse.swt.layout.FormD
import org.eclipse.swt.layout.FormL
import org.eclipse.swt.layout.GridD
import org.eclipse.swt.layout.GridL
import org.eclipse.swt.widgets.B
import org.eclipse.
import org.eclipse.
import org.eclipse.swt.widgets.D
import org.eclipse.swt.widgets.L
import org.eclipse.swt.widgets.S
* This class implements a web browser
public class TestBrowser {
// The "at rest" text of the throbber
private Button button_
private Button button_
private Browser browser2;
private Button button_
private Button button_
private static final String AT_REST = "Ready";
private String[] urlList = new String[256];
int urlListItemCount = 0;
* Runs the application
* @param location
the initial location to display
public void run(String location) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Job36 行业招聘网 CRM系统");
createContents(shell, location);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
display.dispose();
* Creates the main window's contents
* @param shell
the main window
* @param location
the initial location
public void createContents(Shell shell, String location) {
shell.setLayout(new FormLayout());
// Create the composite to hold the buttons and text field
Composite controls = new Composite(shell, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
controls.setLayoutData(data);
// Create the status bar
status = new Label(shell, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
status.setLayoutData(data);
// Create the web browser
browser = new Browser(shell, SWT.BORDER);
browser.addOpenWindowListener(new OpenWindowListener() {
public void open(WindowEvent event) {
Browser browsertest = (Browser)event.
final Shell shell = browser.getShell();
System.out.println(null==browsertest?"为null":browsertest.getUrl());
String urlStr = event.browser.getUrl();
int flag = 1;
browser.setVisible(false);
browser2.setVisible(true);
event.browser = browser2;
for (int i = 0; i & urlListItemC i++) {
if (urlList[i].equals(urlStr)) {
if (flag == 1) {
urlList[urlListItemCount] = urlS
url.add(urlStr);
url.setText(urlStr);
urlListItemCount++;
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
// Create the web browser
browser2 = new Browser(shell, SWT.BORDER);
browser2.addOpenWindowListener(new OpenWindowListener() {
public void open(WindowEvent arg0) {
String urlStr = arg0.browser.getUrl();
int flag = 1;
browser2.setVisible(false);
browser.setVisible(true);
arg0.browser =
for (int i = 0; i & urlListItemC i++) {
if (urlList[i].equals(urlStr)) {
if (flag == 1) {
urlList[urlListItemCount] = urlS
url.add(urlStr);
url.setText(urlStr);
urlListItemCount++;
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser2.setLayoutData(data);
// Create the controls and wire them to the browser
controls.setLayout(new GridLayout(7, false));
// Create the back button
button_back = new Button(controls, SWT.PUSH);
button_back.setText("后退");
button_back.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.back();
// Create the forward button
button_forward = new Button(controls, SWT.PUSH);
button_forward.setText("前进");
button_forward.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.forward();
// Create the refresh button
button_refresh = new Button(controls, SWT.PUSH);
button_refresh.setText("刷新");
button_refresh.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.refresh();
// Create the stop button
button_stop = new Button(controls, SWT.PUSH);
button_stop.setText("停止");
button_stop.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.stop();
// Create the address entry field and set focus to it
url = new Combo(controls, SWT.ARROW_DOWN);
url.setLayoutData(new GridData(296, SWT.DEFAULT));
url.setSize(600, url.getSize().y);
url.setFocus();
// Create the go button
button = new Button(controls, SWT.PUSH);
button.setText("Go");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
String urlStr = url.getText();
int flag = 1;
browser.setUrl(urlStr);
for (int i = 0; i & urlListItemC i++) {
if (urlList[i].equals(urlStr)) {
if (flag == 1) {
urlList[urlListItemCount] = urlS
url.add(urlStr);
urlListItemCount++;
// Create the animated "throbber"
throbber = new Label(controls, SWT.NONE);
throbber.setText(AT_REST);
// Allow users to hit enter to go to the typed URL
shell.setDefaultButton(button);
// Add event handlers
browser.addCloseWindowListener(new AdvancedCloseWindowListener());
browser.addLocationListener(new AdvancedLocationListener(url));
browser.addProgressListener(new AdvancedProgressListener(throbber));
browser.addStatusTextListener(new AdvancedStatusTextListener(status));
// Go to the initial URL
if (location != null) {
browser.setUrl(location);
* This class implements a CloseWindowListener for TestBrowser
class AdvancedCloseWindowListener implements CloseWindowListener {
* Called when the parent window should be closed
public void close(WindowEvent event) {
// Close the parent window
((Browser) event.widget).getShell().close();
* This class implements a LocationListener for TestBrowser
class AdvancedLocationListener implements LocationListener {
// The address text box to update
* Constructs an AdvancedLocationListener
* @param text
the address text box to update
public AdvancedLocationListener(Combo text) {
// Store the address box for updates
location =
* Called before the location changes
* @param event
public void changing(LocationEvent event) {
// Show the location that's loading
location.setText("加载 " + event.location + "...");
* Called after the location changes
* @param event
public void changed(LocationEvent event) {
// Show the loaded location
location.setText(event.location);
* This class implements a ProgressListener for TestBrowser
class AdvancedProgressListener implements ProgressListener {
// The label on which to report progress
* Constructs an AdvancedProgressListener
* @param label
the label on which to report progress
public AdvancedProgressListener(Label label) {
// Store the label on which to report updates
progress =
* Called when progress is made
* @param event
public void changed(ProgressEvent event) {
// Avoid divide-by-zero
if (event.total != 0) {
// Calculate a percentage and display it
int percent = (int) (event.current / event.total);
progress.setText(percent + "%");
// Since we can't calculate a percent, show confusion :-)
progress.setText("完成");
* Called when load is complete
* @param event
public void completed(ProgressEvent event) {
// Reset to the "at rest" message
progress.setText(AT_REST);
* This class implements a StatusTextListener for TestBrowser
class AdvancedStatusTextListener implements StatusTextListener {
// The label on which to report status
* Constructs an AdvancedStatusTextListener
* @param label
the label on which to report status
public AdvancedStatusTextListener(Label label) {
// Store the label on which to report status
* Called when the status changes
* @param event
public void changed(StatusTextEvent event) {
// Report the status
status.setText(event.text);
* The application entry point
* @param args
the command line arguments
public static void main(String[] args) {
new TestBrowser().run(args.length == 0 ? null : args[0]);
挺好的,谢谢。你够用就行,好久没有看过了,之前写的。多的功能你要自己看api了。呵呵。
wangzi6hao
浏览: 149208 次
可以运行了,感谢师兄的慈悲加护!阿弥陀佛
很好,可以跑..谢谢了,我参考下..
验证网址那个方法,我直接输入sjkdasj这样的字符串返回也是 ...
表示运行不了
一模一样哦> Android浏览器怎么打开本地html文件
Android浏览器怎么打开本地html文件
luhuiet & &
发布时间: & &
浏览:2 & &
回复:0 & &
悬赏:0.0希赛币
Android浏览器如何打开本地html文件
]Android浏览器如何打开本地html文件Android
01:02:32 阅读74 评论0 字号:大中小转自:Java语言: Codee#9727Intent intent=new Intent(); intent.setAction("android.intent.action.VIEW"); Uri CONTENT_URI_BROWSERS = Uri.parse("content://colfileprovider/sdcard/123.html"); intent.setData(CONTENT_URI_BROWSERS); intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity"); startActivity(intent);假设要打开的本地html文件存放在如下路径 /sdcard/123.html
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&11:47 提问
在webview中打开一个本地的html文件
在一个根文件夹中保存了一个文件,我想在webview中打开它。
这是我保存文件的代码:
OutputStream outstream =
outstream = openFileOutput(fileName ,MODE_WORLD_READABLE);
if (outstream != null) {
OutputStreamWriter outputreader = new OutputStreamWriter(outstream);
BufferedWriter buffwriter = new BufferedWriter(outputreader);
buffwriter.write(result);
outstream.close();
} catch (java.io.FileNotFoundException e) {
System.out.println("File not found in the writing...");
} catch (IOException e) {
System.out.println("In the writing...");
然后又回调文件:
fileView.getSettings().setJavaScriptEnabled(true);
fileView.loadUrl("file:///" + name); &---
然后程序中我就获得错误提示说不能找到这个文件。
是代码方面出现问题了吗?
按赞数排序
事实上,当你打开一个URL时,要使用file:///...
也就是说你应该在assets目录(test.html)下保存文件。现在假设你需要访问test.html文件,你应该这样写:loadURL("file:///android_asset/test.html');
试一下这个方法:
WebView mWebView=(WebView)findViewById(R.id.mWebView);
mWebView.loadUrl("file:///book.html");
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSaveFormData(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.setWebViewClient(new MyWebViewClient());
private class MyWebViewClient extends WebViewClient
//在webview中显示web页面,但不是在web浏览器
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl (url);
其他相似问题Android浏览器如何打开本地html文件 -
- ITeye技术网站
]Android浏览器如何打开本地html文件
01:02:32 阅读74 评论0 字号:大中小
转自:/wangysh/blog/item/4aaea.html
Java语言: Codee#9727
Intent intent=new Intent();
intent.setAction("android.intent.action.VIEW");
Uri CONTENT_URI_BROWSERS = Uri.parse("content://com.android.htmlfileprovider/sdcard/123.html");
intent.setData(CONTENT_URI_BROWSERS);
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
startActivity(intent);
假设要打开的本地html文件存放在如下路径 /sdcard/123.html
浏览: 38668 次
来自: 北京
试过。。没用.
Bitmap myCoolBitmap = . ...
好的好的好的好的好的好的
好,太好了,帮我解决了一个问题。
我今天也使用了android自带的Geocoder类 发现用这 ...html文件在浏览器中不能显示图片解决方案 - Java Web开发当前位置:& &&&html文件在浏览器中不能显示图片解决方案html文件在浏览器中不能显示图片解决方案&&网友分享于:&&浏览:0次html文件在浏览器中不能显示图片大家好,我在eclipse中建立一个动态web项目,里面想放一张图片,在eclipse中能显示图片,但我在浏览器中看不到图片,网上说是路径的问题,但我觉得不是,请大家帮我分析下。附上我的原代码:
&!DOCTYPE&html&
&meta&charset="UTF-8"&
&title&StudyFile&/title&
&p&This&is&a&paragraph!&/p&
&p&This&is&an&other&paragraph!&/p&
&img&src="F:/Photos/0.jpg"width&=&"30%"&height&=&"50%"/&
&a&href=""&This&is&a&link!&/a&
图片放在F:/Photos/0.jpg中,eclipse中能显示,但在浏览器中只有一个空白边框显示,附上图片,请知道的朋友帮忙解决下。
IE浏览器界面
eclipse界面------解决思路----------------------把src改成相对路径试试,把F:/去掉试试,还有把photos这个文件夹放在WebRoot下面------解决思路----------------------一般不要用本地磁盘
①你可以在项目下创建img文件夹
或②在服务器上放置图片------解决思路----------------------引用:一般不要用本地磁盘
①你可以在项目下创建img文件夹
或②在服务器上放置图片
&img&src="img/0.jpg"/&------解决思路----------------------浏览器右键,查看图片属性.看路径到底是啥------解决思路----------------------路径不对,应该用你项目中的路径------解决思路----------------------F:/Photos/0.jpg
路径问题阿------解决思路----------------------应该是项目中的路径不是本地的------解决思路----------------------如果你非要用盘符的话,那就在tomcate目录下的server.xml中配置下虚拟目录,在JSP页面中直接用就可以了。
一般情况下,对于图片是直接建一个images文件夹,然后把图片放入里面。至于页面上想显示出来,一般都是.....&img&src="&%=request.getContextPath()%&/images/xxx.xxx(图片)"&&,如果不涉及到SpringMVC的资源拦截,应该就能显示出来了------解决思路----------------------你要把图片放入到tomcat下而不是本地,如果要放本地也行,但是要配置虚拟目录的------解决思路----------------------文件路径不要放在tomat中app目录里,或者如楼上,给个虚拟目录也行.
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有

我要回帖

更多关于 浏览器打不开本地html 的文章

 

随机推荐