I have used JQuery to load the small part of my JSP page but I am getting 404 Not Found error. I have placed the home.jsp with sample.jsp. I have written a html form in sample.jsp file and have loaded the same file to a div in home.jsp using load() method of JQuery.
我已经使用JQuery加载了JSP页面的一小部分,但是我得到了404 Not Found错误。我已经把房子安置好了。与sample.jsp jsp。我已经在示例中编写了一个html表单。jsp文件,并已将相同的文件装入家中的div。使用JQuery的jsp load()方法。
home.jsp
<div id="app"></div>
<script type="text/javascript">
$(function() {
$( "#app" ).load( "templates/form-signin.html" );
});
</script>
2 个解决方案
#1
1
Check the URL which gives you 404 in the network tab of your browser's developer options. Then check if you can open it manually. You'll probably get a 404 this way too. Make sure the file is accessible on that URL and adjust the location/server settings/url accordingly.
在浏览器的developer options的network选项卡中检查给您404的URL。然后检查是否可以手动打开。你可能也会得到404页面。确保该文件在该URL上是可访问的,并相应地调整位置/服务器设置/ URL。
#2
1
Ok, I solved it. Instead of a JQuery load() call, I have created an API that serve that sample.jsp file with a HTML form inside the div of home.jsp.
好的,我解决了它。我没有调用JQuery load(),而是创建了一个服务于该示例的API。jsp文件,在home.jsp div中包含一个HTML表单。
home.jsp
<div id="app"></div>
<script type="text/javascript">
$(function() {
$( "#app" ).empty();
$.ajax({
type: "GET",
url: "http://localhost:8080/appname/loginform",
cache: false,
success: function(data){
$("#app").append(data);
}
});
});
</script>
Now the above API call with return that form and it will display inside div tag. It works find whether the sample.jsp is in views folder or inside views/templates folder.
Thank you all for your help.
谢谢大家的帮助。
#1
1
Check the URL which gives you 404 in the network tab of your browser's developer options. Then check if you can open it manually. You'll probably get a 404 this way too. Make sure the file is accessible on that URL and adjust the location/server settings/url accordingly.
在浏览器的developer options的network选项卡中检查给您404的URL。然后检查是否可以手动打开。你可能也会得到404页面。确保该文件在该URL上是可访问的,并相应地调整位置/服务器设置/ URL。
#2
1
Ok, I solved it. Instead of a JQuery load() call, I have created an API that serve that sample.jsp file with a HTML form inside the div of home.jsp.
好的,我解决了它。我没有调用JQuery load(),而是创建了一个服务于该示例的API。jsp文件,在home.jsp div中包含一个HTML表单。
home.jsp
<div id="app"></div>
<script type="text/javascript">
$(function() {
$( "#app" ).empty();
$.ajax({
type: "GET",
url: "http://localhost:8080/appname/loginform",
cache: false,
success: function(data){
$("#app").append(data);
}
});
});
</script>
Now the above API call with return that form and it will display inside div tag. It works find whether the sample.jsp is in views folder or inside views/templates folder.
Thank you all for your help.
谢谢大家的帮助。