top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to write java code inside the html?

0 votes
327 views

We are creating one application in android.on that we have to write java code inside the html file. If I click the button in html page means it will execute in java class.how to do this?

posted Sep 4, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

0 votes

You can use script tag with type as text/javascript to put the code inside HTML.

<html>
<body>
<script type='text/javascript'>
    document.write("java.version " + java.lang.System.getProperty("java.version"));
</script>
</body>
</html>

If you have a button-HTML and you want to call certain function then you can do in the following way

<input name="mydoc" onclick="return my_java_func()" > 

If looking something different then please comment with proper info.

answer Sep 4, 2014 by Salil Agrawal
0 votes

Simply use Java Server Pages i.e JSP. By using this you will be able to write java code inside HTML pages. But remember using the java code inside html doesn't considered to be a good measure.
Generally a professional developer never uses JAVA code inside HTML pages. It is considered to be a very old method.

answer Sep 4, 2014 by anonymous
0 votes

By using JQuery, you can invoke the Java object and call it's methods where by data will be received in JSON format.By doing this, you can keep the Presentation and Business layer different.

answer Sep 4, 2014 by anonymous
Similar Questions
+3 votes

Implement a code that counts the occurrences of each word in an input file and write the word along with corresponding count in an output file sorted by the words alphabetically.

Sample Input

Gaurav is  a Good Boy
Sita is a Good Girl
Tommy is  a Good Dog
Ram is a Good person

Sample Output

D:\>Java FileWordCount inputFile.txt outputFile.txt
    Boy : 1
    Dog : 1
    Gaurav : 1
    Girl : 1
    Good : 4
    Ram : 1
    Sita : 1
    Tommy : 1
    a : 4
    is : 4
    person : 1
0 votes

Like I have a tiny java game in which name of movie is hidden and we have to guess that. Here if your guess is correct that letter will appear at correct place and if wrong you will loose one chance. When we run the code, it runs sometimes without taking any input which it should not do. The java code is following.

import java.util.*;
import java.io.*;
import java.lang.*;
class StrDemo
{
    static StringBuilder change(StringBuilder sb)
    {
        StringBuilder sb1=new StringBuilder("");
        int len=sb.length();
        for(int i=0;i<len;i++)
        {
            if(sb.charAt(i)!=' ')
                sb1.append("*");
            else
                sb1.append(" ");
        }
        return sb1;
    }

    public static void main(String a[])
        throws Exception
        {
            StringBuilder sb2=new StringBuilder("hum sath sath hain");
            StringBuilder sb3=change(sb2);
            int j=0;
            StringBuilder sb4=new StringBuilder("Bollywood");

            while(true)
            {
                System.out.println(sb4);
                System.out.println(sb3);
                System.out.println("Enter Char");

                Scanner sc=new Scanner(System.in);

                char ch=(char)System.in.read();
                int c=0;
                int len=sb2.length();

                for(int i=0;i<len;i++)
                {
                    if(sb2.charAt(i)==ch)
                    {
                        sb3.setCharAt(i,ch);
                        c++;
                    }
                }

                if(c==0)
                    sb4.setCharAt(j++,'*');

                if(sb4.equals("*********"))
                    System.out.println("you lost...");
                else if(sb3.equals("hum sath sath hain"))
                    System.out.println("...u won");
            }   
        }
}
+2 votes

I have some work to deal with directory upload..We can do individual file upload, but I want to know entire directory upload which will contain multiple files...

...