• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to access java script file from jsp page

 
Saw Theingy
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first time of using this forum. So if there is anything mistake or misunderstanding, please teach me everybody.

I am using struts2 framework for my project .
What I want to do is , I want to make client side validation using jquery.
Want to show error message in japanese language , or english according to user choice.
I already done this project with message properties. It was successful.
But Now is want to use jquery for client side validation.
Now my problem is message is not showing with English language.

Please anybody can help me?

Here is my code. This is my second jsp page.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration Form</title>
<link href="css/mystyle.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="Js/errormessage_jp.js"></script>
<script type="text/javascript" src="Js/errormessage_en.js"></script>
<script type="text/javascript" src="Js/jquery.1.9.0.js"></script>
<script type="text/javascript" src="Js/JQuery.validation.1.9.0.js"></script>
<%if ("en".equals(ActionContext.getContext().getLocale().getLanguage().toString())) {
%>
<script type="text/javascript" src="Js/errormessage_en.js"> </script>
<script type="text/javascript">alert("en"+userError12)</script>
<%;}
else if ("jp".equals(ActionContext.getContext().getLocale().getLanguage().toString())) {
%>
<script type="text/javascript" src="Js/errormessage_jp.js"> </script>
<script type="text/javascript">alert("jp"+userError12)</script>
<%;}%>
<script type="text/javascript">
$(document).ready(function() {
$("#myForm").validate({
rules : {
first : {
required : true
}
},
messages : {
first : {
required : userError12
}
}
});
});
</script>
</head>
<body>
Welcome
<s:property value="#session.name" />
!
<h6 align="right">
<s:a href="logoutAction">log out</s:a>
</h6>
<s:head />
<div id="panel">
<s:form id="myForm" action="showResult" namespace="/">
<s:textfield id="first" name="first" key="global.first"
maxLength="10" required="true" size="20" />
<s:submit name="submit" key="global.submit" /></s:form>
</body>
</html>
....
in my message_en.js > var userError12 = "Name";
in my message_jp.js > var userError12 = "名前";

If I choose english language in login page (first page )then alert is showing .. en 名前 , if I choose japanese language in login then alert is show jp 名前 .
When I submit, only error message 名前is showing in both english or japanese page.

Please help me



 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please format your code using the "Code" tags. There is a bunch of FAQs on this site on how to make posts readable.

 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you look at the html source on the page in error and see which <script> actually ended up there? Perhaps your scriptlet is not doing the right thing. It may be helpful to print out what the result of this call actually is :

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic