简体   繁体   中英

Using value returned from a method in other method in java

Plz tell me how can we use value returned from one method in other method in jsp page.. I have two methods in jsp page as given below:

public String method1()
{
   dESEncryption = new DESEncryption();
   enteredValue = req.getParameter("t1");
   encryptedText = dESEncryption.encrypt(enteredValue);
   return encryptedValue;
}

I want to use this encryptedValue in other method public String method2(){}.How can I do it?Plz suggest me.

Try this

public String method1()
{
   dESEncryption = new DESEncryption();
   enteredValue = req.getParameter("t1");
   encryptedText = dESEncryption.encrypt(enteredValue);
   return encryptedText;
}

You did not return the encrypted value, but the original text you got from the request. Also, be careful for any kinds of injections, your code can be prone to quite some nasty attacks without escaping every input...

First of all, it's not really adviced to define methods like that in JSP. Better use tags for it or functions and try to keep your Java code out of your mark-up. This will keep your JSP code cleaner.

But if you really need to call another method then just do it like you do it in Java. This article has some examples.

Simply this won't work?

public String method2()
{
String encryptedVal = method1();

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM