Displaying an html page in form (error connecting to stream) - java-me

I putted an .html page in a src folder of project in order to display this page on runtime.
But I get an error on runtime that say:- Error connecting to stream.
import javax.microedition.midlet.*;
public class HtmlMidlet extends MIDlet {
public void startApp()
{
com.sun.lwuit.Display.init(this);
final com.sun.lwuit.Form form = new com.sun.lwuit.Form("");
final com.sun.lwuit.html.HTMLComponent htmlC = new com.sun.lwuit.html.HTMLComponent( );
htmlC.setRTL(true);
htmlC.setPage("jar://src/ahlam.html");
form.addComponent(htmlC);
form.setScrollable(true);
form.show( );
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
}

I think that the way that you are using to open your file is not the proper way. Is this html page in your folder? Where is your page? the root directory is /src from your project, why are you using jar:... try /ahlam.html only
Take a look on this page for more info and examples HTML Component

Related

How to insert code in the static files like .html, .htm, .asp on IIS for non-asp project

I want to add a script on my IIS Server.
So that it will be applied on all the websites that are upload will have that script in their request response.
Anyone who knows how to do it?
I had implemented the IHttpModule and IHttpHandler, it works fine for the asp.net projects.
but if the website contains only html, css, and js files in the folder, this solution doesn't work.
Here the HttpModule and HttpHandler
public class MyCustomHttpModuleClass : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PostRequestHandlerExecute += OnPostRequestHandlerExecute;
}
public void OnPostRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication application = sender as HttpApplication;
HttpContext context = application.Context;
context.Response.Write("<h1>alert('HELLO')</h1>");
}
}
public class MyHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write("<h1>alert('HELLO')</h1>");
}
}
I'm not sure if you have learnt how to add Custom Module and Handler in IIS. After tested your module and handler with static website, it works fine.
I will just give you a sample of adding them to IIS.
1.Create a project "class library .netframework". I name the project"ClassLibrary1"
2.Add class "MyCustomHttpModuleClass" and "MyHandler" to the project
3.Build this solution and find "ClassLibrary1.dll" in the "project/bin/debug" folder.
4.Copy "ClassLibrary1.dll" to the website root "BIN" folder.
5.Add managed module and handler by choose your dll.(should in the list after you copied)Just mention that your custom handler only work on the file extension you set up.
Now they work.

Install a plugin to Liferay's editor

I have a Liferay DXP installation and I would like to install a plugin to the editor. The plugin is base64image.
I was following this official guide so I created a class generally like this:
#Component(immediate = true, service = DynamicInclude.class)
public class CKEditorBase64ImageDynamicInclude implements DynamicInclude {
private BundleContext bundleContext;
#Override
public void include(HttpServletRequest request, HttpServletResponse response, String key) throws IOException {
Bundle bundle = bundleContext.getBundle();
URL entryURL = bundle.getEntry("/META-INF/resources/html/editors/ckeditor/extension/base64_images.js");
StreamUtil.transfer(entryURL.openStream(), response.getOutputStream());
}
#Override
public void register(DynamicIncludeRegistry dynamicIncludeRegistry) {
dynamicIncludeRegistry.register("com.liferay.frontend.editors.web#ckeditor#onEditorCreate");
}
#Activate
protected void activate(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
}
It should include the base64_images.js file where it initializes the editor. But it never works, regardless what the content of the file is. What is wrong with that?
I would like to add that the plugin files (JavaScript code) are part of my Liferay theme. I wanted base64_images.js to call its API but it also might not be the correct way how to do it.

ServiceStack SelfHosted Site Default page

I have tried all the Razor self-hosted and the servicestack templates and in those projects it is possible to serve static html and cshtml if you have the razorFormat installed. I don't know what I am doing wrong and I have just copied code into new solutions and I cannot get html responses to work. I can get the metadata page always and the services work. I am not able to add default.htm and get it to work.
If I type in http://localhost:1337 I should get directed to the default page. Maybe I am missing something but I don't know what it is. If someone can give me a hand I would appreciate it greatly!
Here is my default.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
SOMETEXT
</body>
</html>
Here is my Program
class Program
{
[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
public class HelloService : Service
{
public object Any(Hello request)
{
return new HelloResponse { Result = "Hello, " + request.Name };
}
}
public class AppHost : AppHostHttpListenerBase {
public AppHost() : base("StarterTemplate HttpListener", typeof(HelloService).Assembly) {
}
public override void Configure(Funq.Container container) {
container.Register(new HelloService());
}
}
static void Main(string[] args)
{
var listeningOn = args.Length == 0 ? "http://*:1337/" : args[0];
var appHost = new AppHost();
appHost.Init();
appHost.Start(listeningOn);
Console.WriteLine("AppHost Created at {0}, listening on {1}", DateTime.Now, listeningOn);
Console.ReadKey();
}
}
Edit:
I should have added what the response I am getting is.
Handler for Request not found:
Request.HttpMethod: GET
Request.HttpMethod: GET
Request.PathInfo: /default.htm
Request.QueryString:
Request.RawUrl: /default.htm
One more thing that I tried was to put a request filter in at AppHostHttpListenerBase.Configure. I do not ever even hit that in my project but I do in the template projects.
EDIT:
I found out that the problem is that my Default.html and app.Config files are not getting moved to the bin/Debug directory. Has anyone experienced that problem?
Here is a good blog post on serving Razor pages for a self-hosted/console app. I don't think you need an app.config or web.config file, though I could be wrong.
The two things I think that you're missing:
1) Add Plugins.Add(new RazorFormat()) to the Configure method in your AppHost
2) Change 'Copy to Output Directory' value to 'Copy if newer' for your Razor files (this is within the Properties settings of the file). Also, change your default.htm file to default.cshtml.
For xamarin in OS X 'Copy to Output Directory' will definitely be a pain in the ass, because you should select this option on each file, and sometimes twice. So another option is create symbolic link
ln -s /path_to_project/assets /path_to_project/bin/Debug/assets
ln -s /path_to_project/Views /path_to_project/bin/Debug/Views
It's very useful for hundreds of files in assets and just a little bit easier for Views folder.
The same can be done on Linux hosting to hide selfhost.exe and *.dll in bin folder

using lwuit UI library I am not destroy j2me application

I am working with j2me using lwuit I have one problem is that
when I am startApp() inside midlet I first set Display.init(this)
and run application lwuit work good but when I am using Form inside startApp() event in midlet it good work but in this form actionevent I am call new form and in this new form
I put one back command when I pressed it it does not move on main midlet
please help how know lwuit use
import javax.microedition.MIDlet;
import some lwuit UILibrary
public class mainMiddlet extends MIDlet implement ActionListner
{
public mainMiddlet(){
try{
Display.init(this);
//somthing is here
form=new Form();
form.addActionListener(this);
}catch(Exception e){}
}
public void actionperformed(ActionEven ae){
//here i call new form
//in action event of this form
new form().show();
}
//here some middlet default method
}
public class newForm extends Form {
//in this form I am put one command back and when i am pressed it
// I call mainMiddlet but it throw error internal application java.lang.nullpointer
// can I back on mainmiddlet from on form to another form
// my main problem is I am not move on mainmiddlet for exit middlet because destoryall()
// is method of middlet
}
Its just simple. You can call the show() method inside next form back command. For example,
MainMidlet.java
// create the midlet and write inside of the midlet
final Form form = new Form();
form.addCommand(new Command("Next") {
public void actionPerformed(ActionEvent evt) {
new NewForm(form).show();
}
});
NewForm.java
// create the NewForm class and write inside of the class
public NewForm(final Form form) {
// Constructor
addCommand(new Command("Back") {
public void actionPerformed(ActionEvent evt) {
form.show();
}
});
}

C# Webbrowser control - Defining document loaded

DocumentCompleted will work after all dom elements loaded (images, flash and etc.). And I am waiting when all dom elements are downloaded to work this document. How can I define when documnet (page) loaded (when client see the page)? Is there any event to define when document LOADED to client?
Why not let the page raise an event? For instance, something like:
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TestWebBrowser
{
[ComVisible(true)]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, System.EventArgs e)
{
webBrowser1.ObjectForScripting = this;
webBrowser1.DocumentText = #"
<html>
<body onLoad='jscript:window.external.DocumentLoaded();'>
<img src=""http://www.nasa.gov/images/content/464377main_image_1695_1600-1200.jpg"" />
</body>
</html>";
}
public void DocumentLoaded()
{
MessageBox.Show("Document Finished Loading.");
}
}
}
In the above sample the page uses the onLoad() event to notify the form when the page has finished loading.
Hope this helps.

Resources