Assign javascript variable to jsp variable

Struct with the below scenario ? ,

String version ="<script>document.write(get_version);</script>";
out.println(version); -------> 1.0

but version = "<script>document.write(get_version);</script>" still and are you unable to use the version variable in JSP and want to fix this issue.

Guys am here to help you out even in this tough situation. You should not suffer as I suffered to fix this issue. Please follow the below steps and make yourself great and fix the issue. Everything is possible in Java.

Assign javascript variable to jsp variable, or use javascript variable to jsp variable or pass hidden value to JSP page from another page where you are uploading a file with post method and still you want to pass a html element value from post form where you want the get method logic. Here below the great example. Try to understand the below scenario and your issue is fixed.

Current JSP or HTML form page : 

Currentpage.jsp

document.getElementById("myForm").submit();
document.myForm.action = "uploadget.jsp?hiddenVersion="+document.getElementById("version").value;
alert("File Uploaded Successfully");


 <form name="myForm" enctype="multipart/form-data" method="post" onsubmit="return validateForm();" id="myForm">
 <input type="hidden" name="hiddenVersion" id="hiddenVersion" value="">
.....
<input type="text" id="version" name="version">
......
</form>


And in your action JSP use this,

request.getParameter("hiddenVersion");

and thats it.

Features of Java

The features of Java are,

Simple - Java is very simple programming to learn which is based on C++. No complex terms like explicit pointers and operator overloading etc. No need to destroy objects at the end after usage because there is auto destruction of objects in java named as Garbage Collection.
Object Oriented - Simplified software development and rules and maintenance is easier. The basic concept of oops are object, class, inheritance, polymorphism, abstraction, encapsulation, dynamic binding, message parsing.
Platform Independent - Compile it once and run it in any platform like windows, linux, solaris, etc... Java code units are converted into byte code  by the compiler. This byte code is platform independent.
Secured - Java is secured because there are no pointers and the program runs inside the virtual machine.
Robust - Java is strong in memory management.
Portability - Java byte code can be run in any platform and it can be carried anywhere in any platform.
Interpreted
Multi threading - Multiple tasks using multiple threads sharing same memory. Threads are separate program which runs concurrently.
High Performance - Java is faster.
Distributed - We can create distributed apps in Java.

The above terms are also called as buzz words in Java.

Genetic Algorithm Java Example

Genetic algorithm is a part in evolutionary computing and it is growing rapidly in the area of artificial intelligence. Let us discuss about this concept in the below link.


Applications of GA (Genetic Algorithm) are used in engineering, computational science, physics, chemistry, mathematics, manufacturing, economics, pharmacometrics, bio informatics, phylogenetics, and in many other fields.

Right Click JTextField cut copy paste

In this post you can learn an example on how to implement right click option for cut, copy and paste in a JTextField in java swings. This concept is used in many swing application development.

      JTextField textfield;
      textfield = new JTextField(15);
    
      JPopupMenu popup = new JPopupMenu();
      JMenuItem item = new JMenuItem(new DefaultEditorKit.CutAction());
      item.setText("Cut");
      popup.add(item);
      item = new JMenuItem(new DefaultEditorKit.CopyAction());
      item.setText("Copy");
      popup.add(item);
      item = new JMenuItem(new DefaultEditorKit.PasteAction());
      item.setText("Paste");
      popup.add(item);
      textfield.setComponentPopupMenu(popup);

Change value of static variable by method

Actually we have learned that static variable does not change its value and it is not possible to change the value of a static variable. But in this post you can learn an example in java on how to change the value of a static variable by using a method in java.

InitializeByMethod.java

package com.udhaya;

class StaticDemo {
        static String name;
public static void staticVariable() {
        name = name + " " + "kumar";
        System.out.println("Value of static variable after method calling"
                + name);
        }
}
public class InitializeByMethod {
public static void main(String[] args) {
        System.out.println("Initial value of static variable"
                        + StaticDemo.name);
        StaticDemo.name = "udhaya";
        System.out.println("Value of static variable after initialization"
                        + StaticDemo.name);
        StaticDemo.staticVariable();
        }
}
My Profile