admin管理员组文章数量:1406950
I really did not want to be posting this, but here I am. It looks like I have been unable to find any way to simply display a java variable in an html doc. I have a feeling this isn't possible and I should be using javascript or something else but I would love it if someone could point me in the right direction.
My Java code is simple and basically just creates a single int that I would like to use in my html doc. For arguments sake let's imagine this:
JAVA CODE
public class Counter {
public static void main(String[] args) {
int number = 24;
}
}
Once again for argument sake
HTML CODE
<HEAD>
<script src="java/counter.java"></script>
</HEAD>
I've looked into things like document.write() and Element.innerHTML but I believe these things are probably associated with Javascript and/or JSP. I'm expecting more of an explanation rather than some simple code since I'm sure I'm going about this wrong. Just want to know how I should create my "counter", whether it be in Javascript or something else. I am using PHP and CSS so I also am also not sure if I should be using those to access my programs final int. First dive in to multi language programming so be gentle. Thanks!
I really did not want to be posting this, but here I am. It looks like I have been unable to find any way to simply display a java variable in an html doc. I have a feeling this isn't possible and I should be using javascript or something else but I would love it if someone could point me in the right direction.
My Java code is simple and basically just creates a single int that I would like to use in my html doc. For arguments sake let's imagine this:
JAVA CODE
public class Counter {
public static void main(String[] args) {
int number = 24;
}
}
Once again for argument sake
HTML CODE
<HEAD>
<script src="java/counter.java"></script>
</HEAD>
I've looked into things like document.write() and Element.innerHTML but I believe these things are probably associated with Javascript and/or JSP. I'm expecting more of an explanation rather than some simple code since I'm sure I'm going about this wrong. Just want to know how I should create my "counter", whether it be in Javascript or something else. I am using PHP and CSS so I also am also not sure if I should be using those to access my programs final int. First dive in to multi language programming so be gentle. Thanks!
Share asked Oct 1, 2015 at 3:25 DependableSkeletonDependableSkeleton 111 silver badge2 bronze badges 7- do you have tried java applets, or jsp? – Channa Jayamuni Commented Oct 1, 2015 at 3:29
- I have looked into Java applets as well but to be honest I didn't want to jump in without knowing whether or not that would suite my needs. As for JSP I have no experience and am in the same boat, really just want to know the best way to go about this before I research something new. @ChannaJayamuni – DependableSkeleton Commented Oct 1, 2015 at 3:33
- You need to work with javascript – Sajitha Rathnayake Commented Oct 1, 2015 at 3:34
- If I work with Javascript would I need to work with JSP aswell? Just need to know what I should be googling and I'll get right at it. Thanks! @SajithaNilan – DependableSkeleton Commented Oct 1, 2015 at 3:36
- No. javascript can work with any scripts like HTML, PHP, JSP, ASP – Sajitha Rathnayake Commented Oct 1, 2015 at 3:39
3 Answers
Reset to default 4you have to write your variable like this
"<%= variable name here %>"
in your JSP file
The first thing i have to mention is "YOU CANNOT DO IT WITHOUT AN APPLET OR JAVA WEB SERVER" with live updates of your variable.
- If you don't want to live update your web page, you can create a .html file with java and open it through your browser.
- If you are free to use another programming option you can use javascript instead of java.
- If you need both live update of variable and java as programming language, you should use one of java applets and jsp page with server. I remend to use jsp since it is highly available of resources.
First of all, lets clear smth here. Java is an interpreting language, which means you cannot run java without calling its executable interpreter or a web container or application deployment platform.
If you run java code, very firstly you should pile it and get piled byte code. This would be a ".class" file. Then if you want to run it as standalone application then you should use platform dependent interpreter. For Windows OS, it is "java.exe", for linux platforms it would be "java" executable. For WEB applications there are some sort of containers like Jetty, Tomcat which can run class files and pile (JSP files not java).
Lets assume that, you are using Tomcat with your web application. Then with your app, you can run your code with JSP file or with async call it is difficult in your case.
Find a very simple JSP tutorial and try howto run your code.
本文标签: javascriptDisplaying java variable on html pageStack Overflow
版权声明:本文标题:javascript - Displaying java variable on html page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744950741a2634066.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论