File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to access java script file from jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to access java script file from jsp page " Watch "How to access java script file from jsp page " New topic
Author

How to access java script file from jsp page

Saw Theingy
Greenhorn

Joined: Feb 21, 2013
Posts: 1
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

Joined: Mar 24, 2005
Posts: 186
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

Joined: Mar 24, 2005
Posts: 186
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 :

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access java script file from jsp page