• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to pass javasript variable to java scriplet in side jsp?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a variable passord in my jsp.
I have called a javascript function on submit button, to encrypt the passord variable & agin i need to reset encrypted value to same variable.
So that in POST request decrypted passowrd wont be visible. But i cant access my form variable in my function to encrypt it.
Below is my function code snippet

function encryptData()
{
var conpassword = document.forms[0].confirmPassword.value;
alert('SCRIPT CONpass:::'+conpassword);
<%String stCon="<script>document.writeln(conpassword)</script>";
String stCon1 = new Encrypter(stCon).encrypt(); %>
document.forms[0].confirmPassword.value='<%=stCon1%>';
}

Pleae help me in this
 
Greenhorn
Posts: 13
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,JSP from up to down the compiler,So when the page is loaded after,< % % > between has been compiled output statements.

I think you can use AJAX,DWR.
 
Shweta Machhe
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But when i use this code & prints stCon string using out.println it gives be right value (password enetered n UI), but when i use alert for same value then it gives me value <script>document.writeln(v);</script>. why this diffrenece?
 
Jerome Gao
Greenhorn
Posts: 13
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shweta Machhe wrote:But when i use this code & prints stCon string using out.println it gives be right value (password enetered n UI), but when i use alert for same value then it gives me value <script>document.writeln(v);</script>. why this diffrenece?


May I have a look at the complete code?

Now I guess first print right because JSP are compiled,When you go to save, JSP compiler has already been done!
You can see on the browser after the compilation of the source code,So that you may be able to see some problems!



 
Shweta Machhe
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have never coded in AJAX or DWR could you please guide me on this
 
Shweta Machhe
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is the complete code , i had written it at the top of my JSP.
out.println prints jspvar=======>>>>>>Shweta on my jsp
but logger.info prints value jspvar=======>>>>>><script>document.writeln(v);</script>.

<script>
var v="Shweta";
</script>
<% String jspvar="<script>document.writeln(v);</script>";
out.println("jspvar=======>>>>>>"+jspvar);
logger.info("jspvar=======>>>>>>"+jspvar);
%>
 
Jerome Gao
Greenhorn
Posts: 13
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, this can be printed out is very normal´╝îBut when you print out later,

This code has become

And then output v,"jspvar=======>>>>>>Shweta ",

This piece of code is not exist,So you save it could not be completed!



 
Jerome Gao
Greenhorn
Posts: 13
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
about ajax ,You can find some examples to see it,If there are not understand,Can have asked me




 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The variable contains <script>document.writeln(v)</script>. out.println renders the html content in the page. So, in your case content to be rendered is <script>document.writeln(v)</script>. Now in the rendered html page it gets interpreted as a java script code and writes the value Shweta in the page. But logger.info simply writes the value of the variable i.e <script>document.writeln(v)</script> in the log.
 
Jerome Gao
Greenhorn
Posts: 13
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is very normal,<script>document.writeln(v)</script>,this is the browser analytical,Log is record variable value,Not to do processing,
 
Greenhorn
Posts: 29
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Why do you want to encrypt the password using javascript ? This is highly dangerous for the following reason

1. the algorithm will be exposed on client side for your encryption
2. the browser may have turned off the javascript so your code will not work.

I suggest you to perfor this on the server side.
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic