Im working on a DynamicWebProject in Eclipse IDE.I got an error in console while running a jsp page showing "Failed to load resource: the server responded with a status of 404 (Not Found)".I already referred many questions regarding this problem but could not resolve it.Here is my javascript file
availability.js
var ajaxRequest = null;
if (window.activeXObject) {
ajaxRequest = new ActiveXObject("Microsoft.HTTP");
} else {
ajaxRequest = new XMLHttpRequest();
}
function ajaxValidation() {
var name = document.getElementById("username").value;
ajaxRequest.open("GET", "/SpringHibernateProject/validate?name=" + name,
true);
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
var message = ajaxRequest.responseText;
document.getElementById("div").innerHTML = "<font color='red'>"
+ message + "</font>";
}
};
ajaxRequest.send(null);
}
Here is my jsp page
AjaxPage.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="../Js/availability.js"></script>
</head>
<body>
<input type="text" name="username" id="username" onkeyup="ajaxValidation()"></input>
<div id="div"></div>
</body>
</html>
Im getting this error though I referred the script file correctly.Why is it so?
Related
Root Issue: Unable to get the value in JSP sent by the HTML xhr request.
HTML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js">
</script>
<script>
function click() {
var xhr = null;
if (navigator.appName == 'Microsoft Internet Explorer') {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} else if (navigator.appName == 'Netscape') {
xhr = new XMLHttpRequest();
}
xhr.open('POST', "verify.jsp", true);
var params = 'empIds=' + '123';
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
alert(xhr.responseText);
}
};
xhr.send(params);
}
</script>
</head>
<body>
<p><button onclick="click()" type="button">Click</button></p>
JSP Page
<%# page import="java.io.*" %>
<%# page import="java.util.*" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<BR>
<%
long timeInMilliSeconds = System.currentTimeMillis();
String empId = request.getParameter("empIds");
out.print("emp Id: "+empId);
%>
</BODY>
</HTML>
Actual Result:
empId:
Expected Result:
empId: 123
Please help me where i did the mistake or how to fix it. Basically want to send the value from HTML to JSP. JSP should retrieve the value and send the same value back to HTML
Reason: String empId = request.getParameter("empIds"); is returning null.
Thanks
My error above , I did write.
Now , I have 4 my file.The problem is simple.(denetleme.jsp,BasvuruFormu.jsp,Elemanlar.java) and I want to after in BasvuruFormu.jsp to submit clicked it is going to denetleme.jsp then there applied kontrolMethod after if boolean hata = false I want to OnayYok.jsp but i cant go.
BasvuruFormu.jsp also goes after clicking on the button denetleme.jsp then Elemanlar.java check in KontrolMethod() but boolean hata = false but after freezing false, OnayYok.jsp does not go
1)denetleme.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%# page import="java.util.*" %>
<jsp:useBean id="kahveCekirdegi" class="com.jsp.Elemanlar" scope="request">
<jsp:setProperty property="ad" name="kahveCekirdegi" />
<jsp:setProperty property="yas" name="kahveCekirdegi" />
</jsp:useBean>
<%
if(kahveCekirdegi.kontrolMethod()){
%>
<jsp:forward page="onay.jsp"/>
<%
} else {
%>
<jsp:forward page="OnayYok.jsp"/>
<%
}
%>
</body>
</html>
2)BasvuruFormu.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action = "denetleme.jsp" method = "post">
<table border="1">
<tr>
<td>Ad
<input type = "text" name = "ad"></td>
</tr>
<tr>
<td>Yas
<input type = "text" name = "yas"></td>
</tr>
</table>
<input type = "submit" value = "submit" style="background-color: red; color : black;">
</form>
</body>
</html>
3)Elemanlar.java
package com.jsp;
import java.util.Hashtable;
public class Elemanlar {
private String ad;
private String yas;
private Hashtable<String, String> hatalar;
public void setYas(String yas) {
this.yas = yas;
}
public String getYas() {
return this.yas;
}
public void setAd(String ad) {
this.ad = ad;
}
public String getAd() {
return this.ad;
}
public boolean kontrolMethod() {
boolean hata = true;
if (ad.equals("")) {
hatalar.put("ad", "lütfen ad giriniz");
ad = "";
hata = false;
}
if (yas.equals("")) {
hatalar.put("yas", "Lütfen geçerli bir yaş giriniz");
yas = "";
hata = false;
}
return hata;
}
public String getHataMesajlari(String hataCumleleri) {
String hataMesajlari = (String) hatalar.get(hataCumleleri.trim());
return (hataMesajlari == null) ? "" : hataMesajlari;
}
public void setHatalar(String formElemani, String verilenHataMesaji) {
hatalar.put(formElemani, verilenHataMesaji);
}
}
4)OnayYok.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>Onay yok jsp</h3>
</body>
</html>
Example Ad and Yas is empty photography below.
then I clicked submit
Misateke :
https://i.stack.imgur.com/ay6T7.png
https://i.stack.imgur.com/udYKs.png
I'm using custom.jsp in order to avoid the login screen and load the home screen directly, but still it's asking for login credentials after restarting the tomcat. The path of the custom.jsp file is "SAP BusinessObjects\tomcat\webapps\BOE\WEB-INF\eclipse\plugins\webpath.InfoView\web"
I don't know what I'm missing here and I'm new to this. Below is my jsp code. Thanks.
<%# page import="com.crystaldecisions.sdk.exception.SDKException" %>
<%# page import="com.crystaldecisions.sdk.framework.*" %>
<%# page import="com.crystaldecisions.sdk.occa.infostore.*" %>
<%# page import="com.crystaldecisions.sdk.occa.security.*"%>
<%# page import="java.net.*"%>
<%# page import="com.crystaldecisions.enterprise.*"%>
<%# page import="com.crystaldecisions.sdk.plugin.admin.*"%>
<%# page import="java.sql.*"%>
<%# page import="com.businessobjects.webutil.Encoder" %>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
IEnterpriseSession enterpriseSession;
final String BO_CMS_NAME = "BI98svr";
final String BO_AUTH_TYPE = "secEnterprise";
final String BO_USERNAME = "user121";
final String BO_PASSWORD = "pass121";
ILogonTokenMgr logonTokenMgr;
String defaultToken = "";
boolean loggedIn = true;
try {
enterpriseSession =
CrystalEnterprise.getSessionMgr().logon(BO_USERNAME,BO_PASSWORD,
BO_CMS_NAME,BO_AUTH_TYPE);
logonTokenMgr = enterpriseSession.getLogonTokenMgr();
defaultToken = logonTokenMgr.createWCAToken("", 20, 1);
response.sendRedirect("http://"+BO_CMS_NAME+":8080/BOE/BI/logon/start.do?ivsLogonToken="+Encoder.encodeURL(defaultToken));
}
catch (Exception error)
{
loggedIn = false;
out.println(error);
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
I was trying to return a JSON Object from this jsp page.But I dont know why Its not providing the required results.Here is my jsp page :
<%#page import="net.sf.json.JSONException"%>
<%#page import="net.sf.json.JSONArray"%>
<%#page import="net.sf.json.JSONObject"%>
<%#page contentType="application/json" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="application/json; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
JSONObject json = new JSONObject();
JSONArray employeeslist = new JSONArray();
JSONObject employee;
try
{
int count = 15;
for (int i=0 ; i<count ; i++)
{
employee = new JSONObject();
employee.put("name" , "Decepticons" + i);
employee.put("id" , "1999" + i);
employeeslist.add(employee);
}
json.put("Employeeslist", employeeslist);
}
catch (JSONException jse)
{
}
out.write(json.toString());
%>
</body>
</html>
Please help me to find error in this code.
My ajax calling this jsp :
<script type="text/javascript">
$(document).ready(function() {
$("input[type=button]").click(function () {
$.ajax({
url: 'ValidEmployeeList.jsp',
dataType: 'json',
success: function(data) {
//alert(data);
alert(JSON.stringify(data));
},
error: function() {
alert('error');
}
});
});
});
</script>
You mix Json content type with html format. Try removing html tags at start and end:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="application/json; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
And
</body>
</html>
Finally do not ever use empty catch block. You might miss some important exception that is real cause.
The json variable is never assigned beyond creating the new, empty, JSONObject. You only use employee and employeeslist. But you never print those out.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" `"http://www.w3.org/TR/html4/loose.dtd">`
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.get("JsonCreation.jsp",function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
</head>
<body>
<button>Send an HTTP GET request to a page and get the result back</button>
</body>
</html>
i am trying to get data from db create jsonarray from resultset and use it to populate text box when a tables row is clicked so far i have displayed the data using alert and i am getting the exact data but i want to access column by column and populate corresponding text
<%#page import="org.json.JSONObject"%>
<%#page import="java.lang.Thread.State"%>
<%#page import="org.json.JSONArray "%>
<%#page import="org.json.JSONObject" %>
<%# page language="java" import="java.io.*,java.sql.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
String mySqlUrl = "jdbc:mysql://localhost:3306/permit";
Connection con = DriverManager.getConnection(mySqlUrl ,"root","moodle123");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from enterprisemaster where enterpriseId=1001");
JSONArray respJson = new JSONArray();
java.sql.ResultSetMetaData rsmd = rs.getMetaData();
int numColumns = rsmd.getColumnCount();
while (rs.next()) {
JSONObject obj = new JSONObject();
for (int i = 1; i < numColumns + 1; i++) {
String columnName = rsmd.getColumnName(i);
obj.put(columnName, rs.getString(columnName));
}
respJson.put(obj);
}
respJson.toString();
out.println(respJson);
}
catch(Exception e)
{
System.out.println(e);
}
%>
</body>
</html>
the out put from the alert box is this
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/json; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
[{"phone":"0471-2318922,0435-6203","fax":"0471- 2315893","website":"www.ksidc.org","enterpriseName":"KERALA STATE INDUSTRIAL DEVELOPMENT CORPORATION LIMITED","enterpriseId":"1001","factoryAddress":"","isActive":"1","category":"Financial Services","chairmanName":"Sri.T.K.A.Nair","administrativeDept":"Industries Department","incorporationDate":"21/07/1961","email":"ksidc#vsnl.com","incorporationAct":"Companies Act,1956","mdName":"Sri.Alkesh Kumar Sharma IAS","officeAddress":"T.C.XI/226,Keston Road,Kowdiar,Thriruvananthapuram-695003","activities":"Providing Promotional and financial assistance for industries in Kerala and acting as nodal/implementing/facilitating agency for mega projects"}]
</body>
</html>
Status:success
![alert output its content[1]
[1]: http://i.stack.imgur.com/EIlJw.png
$(document).ready(function(){
$.getJSON("Test.json",function(data){
$.each(data,function(key,value){
alert(data[key].activities);
alert(data[key].enterpriseName);
$('input').val(data[key].enterpriseName);
activities=data[key].activities;
console.log(value);
});
});
});