Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP code is not working in jquery

 
gupta pankaj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\\I am not able to understand the problem.
\\when i miss the jsp code i.e <% all data %> then it work fine, but when i enter the
\\jsp code in it it does not give any output. soo help me out?
\\This is the whole program:


<%@page import="java.io.File"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>

<script>
var str1;
$(document).ready(function(){
$("#dir1").focusout(function(){
$(".test").hide();
alert("Value: " + $("#dir1").val());

<%
String str1 = "d:\\";
File f1 = new File(str1);
File[] contents = f1.listFiles();
for (int j = 0; j < contents.length; j++) {
\\Want to display the files and directories
if (contents[j].isDirectory()) {

out.println("Directory : " + contents[j].getName() + "<br/>");
}
if (contents[j].isFile()) {
out.println("Files :" + contents[j].getName() + "<br/>");
}

}
%>



});
});
</script>
<title>JSP Page</title>

</head>
<body>
<input type="text" name="dir1" id="dir1"/>

</body>
</html>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP code has nothing much to do with jQuery. JSP executes on the server; jQuery on the client. All that matters is what is sent to the browser.

So rather than look at the server-side code, look at what is sent to the browser. Is it correct? Is it valid? What's different?

By the way, Java code in a JSP is a very poor and obsolete practice from 12 years ago. You should no longer be putting Java code in JSPs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic