|
MIND BLOWN !
Thank you so very much! I just yelped with joy, the people around me think I'm crazy. Thank you, thank you, thank you!!!!
|
|
|
|
|
Go to Parent-------------------------------------index.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>
<script type="text/javascript">
var req;
function initReq(){
if(window.XMLHttpRequest){
req=new XMLHttpRequest;
}else if(window.ActiveXObject){
req=new ActiveXObject("Microsoft.XMLHTTP");
}
}//initReq
function verifyUname(){
initReq();
var sid=document.getElementById("uname").value;
var url="checkunm.jlc?uname="+escape(uname);
req.open("GET",url);
req.onreadystatechange=processResponse;
req.send();
}
function processResponse(){
var st=req.readyState;
var resSt=req.status;
if(st==4 && resSt==200){
displayResult();
}
}//processResponse
function displayResult(){
document.getElementById("error").innerHTML="";
document.getElementById("result").innerHTML="";
var array=req.responseText;
var data=eval('('+array+')');
if(data.length==0){
document.getElementById("error").innerHTML="<font color='red' size='5'>no student found</font>";
}//if
else
{
for(var i=0;i<data.length;i++){
var jsob=data[i]; <<<<<<<<<<<<<< ----here value is not coming it is getting 0 each time input----------------
document.write(jsob.msg);
}
}
}
</script>
<body>
<form action="register.jlc" method="post">
<div id="result"></div>
<div id="error"></div>
<table>
<tr>
<td align="center" colspan="2">REGISTER HERE</td>
</tr>
<tr>
<td>
ENTER USERNAME
</td>
<td>
<input type="text" name="uname" id="uname" onkeyup="verifyUname()"/>
</td>
</tr>
<tr>
<td>
ENTER PASSWORD
</td>
<td>
<input type="password" name="password" id="password" onkeyup="verifyUname()"/>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="REGISTER"/>
</td>
</tr>
</table>
</form>
</body>
</html>
------------------------------CheckUnameServlet-------------------------------------------------
package com.jlcindia.ajax;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.JSONArray;
import java.io.IOException;
import java.util.*;
public class CheckUnameServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
ArrayList<String> unames=new ArrayList<String>();
public void init(ServletConfig config) throws ServletException{
unames.add("sri");
unames.add("lucky");
unames.add("piyush");
unames.add("ujjawal");
super.init(config);
}
protected void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
String uname=req.getParameter("uname");
String msg="";
JSONArray array=new JSONArray();
if(uname!=null && uname.trim().length()>0){
JSONObject jobj=new JSONObject();
if(unames.contains(uname)){
try {
jobj.put(msg); <<<<<<<< -------------// here may be am doing wrong --------------
} catch (JSONException e) {
e.printStackTrace();
}
array.add(jobj);// <<<<<<<<< -------------// here may be am doing wrong --------------
System.out.println(array);
}
}
System.out.println(array.toJSONString());
res.setContentType("application/json");
res.getWriter().write(array.toString());
}
}
-----------------------web.xml------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Test2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>cuServlet</servlet-name>
<servlet-class>com.jlcindia.ajax.CheckUnameServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cuServlet</servlet-name>
<url-pattern>/checkunm.jlc</url-pattern>
</servlet-mapping>
</web-app>
|
|
|
|
|
What part of "don't just dump your unformatted code and expect us to figure out what it's supposed to be doing" did you not understand?
Edit your post. Remove any code that isn't relevant. Add a clear description of what the code is supposed to be doing, what the code is actually doing, and the full details of any errors and exceptions. Remember to tell us which line of code the error is thrown from.
And while you're at it, remove the duplicate copy of this post from QA.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i think you are not understanding the code properly just read the subject first and chk the code where i mentioned DID YOU NOT UNDERSTAND .dont just copy and paste your statements
|
|
|
|
|
You have repeatedly been told, by multiple people, not to dump your code and expect us to figure it out.
And yet you continue to dump your code and expect us to figure it out.
We are NOT here to do your job for you. If you can't be bothered to put any effort into asking a question, then why should we bother to try to help you?!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
<%@ 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>
<script type="text/javascript">
var req;
function initReq(){
if(window.XMLHttpRequest){
req=new XMLHttpRequest;
}else if(window.ActiveXObject){
req=new ActiveXObject("Microsoft.XMLHTTP");
}
}//initReq
function verifyUname(){
initReq();
var sid=document.getElementById("uname").value;
var url="checkunm.jlc?uname="+escape(uname);
req.open("GET",url);
req.onreadystatechange=processResponse;
req.send();
}
function processResponse(){
var st=req.readyState;
var resSt=req.status;
if(st==4 && resSt==200){
displayResult();
}
}//processResponse
function displayResult(){
document.getElementById("error").innerHTML="";
document.getElementById("result").innerHTML="";
var array=req.responseText;
var data=eval('('+array+')');
if(data.length==0){
console.log(data);
}//if
else
{
for(var i=0;i<data.length;i++){
var jsob=data[i];
document.createTextNode(jsob.msg);
}
}
</script>
<body>
<form action="register.jlc" method="post">
<div id="result"></div>
<div id="error"></div>
<table>
<tr>
<td align="center" colspan="2">REGISTER HERE</td>
</tr>
<tr>
<td>
ENTER USERNAME
</td>
<td>
<input type="text" name="uname" id="uname" onkeyup="verifyUname()"/>
</td>
</tr>
<tr>
<td>
ENTER PASSWORD
</td>
<td>
<input type="password" name="password" id="password" onkeyup="verifyUname()"/>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="REGISTER"/>
</td>
</tr>
</table>
</form>
</body>
</html>
package com.jlcindia.ajax;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.JSONArray;
import java.io.IOException;
import java.util.*;
public class CheckUnameServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
ArrayList<String> unames=new ArrayList<String>();
public void init(ServletConfig config) throws ServletException{
unames.add("sri");
unames.add("lucky");
unames.add("piyush");
unames.add("ujjawal");
super.init(config);
}
protected void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
String uname=req.getParameter("uname");
String msg="";
JSONArray array=new JSONArray();
if(uname!=null && uname.trim().length()>0){
JSONObject jobj=new JSONObject();
if(unames.contains(uname)){
msg="<message>sorry username is already in use</message>";
}
}
System.out.println(array.toJSONString());
res.setContentType("application/json");
res.getWriter().write(array.toString());
}
}
|
|
|
|
|
CheckUnameServlet.java
package com.jlcindia.ajax;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.JSONArray;
import java.io.IOException;
import java.util.*;
public class CheckUnameServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
ArrayList<String> unames=new ArrayList<String>();
public void init(ServletConfig config) throws ServletException{
unames.add("sri");
unames.add("lucky");
unames.add("piyush");
unames.add("ujjawal");
super.init(config);
}
protected void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
String uname=req.getParameter("uname");
String msg="";
JSONArray array=new JSONArray();
if(uname!=null && uname.trim().length()>0){
JSONObject jobj=new JSONObject();
if(unames.contains(uname)){
try {
jobj.put("msg","<message>sorry username is already in use</message>");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
array.add(jobj);
System.out.println(array);
}
}
System.out.println(array.toJSONString());
res.setContentType("application/json");
res.getWriter().write(array.toString());
}
}
|
|
|
|
|
Please do not just dump a load of unformatted code and expect someone to figure out what it is supposed to be doing. Edit your question and explain the problem properly, with only the relevant portions of the code, properly enclosed within <pre> tags for readability.
|
|
|
|
|
-------------------------------------index.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>
<script type="text/javascript">
var req;
function initReq(){
if(window.XMLHttpRequest){
req=new XMLHttpRequest;
}else if(window.ActiveXObject){
req=new ActiveXObject("Microsoft.XMLHTTP");
}
}//initReq
function verifyUname(){
initReq();
var sid=document.getElementById("uname").value;
var url="checkunm.jlc?uname="+escape(uname);
req.open("GET",url);
req.onreadystatechange=processResponse;
req.send();
}
function processResponse(){
var st=req.readyState;
var resSt=req.status;
if(st==4 && resSt==200){
displayResult();
}
}//processResponse
function displayResult(){
document.getElementById("error").innerHTML="";
document.getElementById("result").innerHTML="";
var array=req.responseText;
var data=eval('('+array+')');
if(data.length==0){
document.getElementById("error").innerHTML="<font color='red' size='5'>no student found</font>";
}//if
else
{
for(var i=0;i<data.length;i++){
var jsob=data[i]; <<<<<<<<<<<<<< ----here value is not coming it is getting 0 each time input----------------
document.write(jsob.msg);
}
}
}
</script>
<body>
<form action="register.jlc" method="post">
<div id="result"></div>
<div id="error"></div>
<table>
<tr>
<td align="center" colspan="2">REGISTER HERE</td>
</tr>
<tr>
<td>
ENTER USERNAME
</td>
<td>
<input type="text" name="uname" id="uname" onkeyup="verifyUname()"/>
</td>
</tr>
<tr>
<td>
ENTER PASSWORD
</td>
<td>
<input type="password" name="password" id="password" onkeyup="verifyUname()"/>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="REGISTER"/>
</td>
</tr>
</table>
</form>
</body>
</html>
------------------------------CheckUnameServlet-------------------------------------------------
package com.jlcindia.ajax;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.JSONArray;
import java.io.IOException;
import java.util.*;
public class CheckUnameServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
ArrayList<String> unames=new ArrayList<String>();
public void init(ServletConfig config) throws ServletException{
unames.add("sri");
unames.add("lucky");
unames.add("piyush");
unames.add("ujjawal");
super.init(config);
}
protected void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
String uname=req.getParameter("uname");
String msg="";
JSONArray array=new JSONArray();
if(uname!=null && uname.trim().length()>0){
JSONObject jobj=new JSONObject();
if(unames.contains(uname)){
try {
jobj.put(msg); <<<<<<<< -------------// here may be am doing wrong --------------
} catch (JSONException e) {
e.printStackTrace();
}
array.add(jobj);// <<<<<<<<< -------------// here may be am doing wrong --------------
System.out.println(array);
}
}
System.out.println(array.toJSONString());
res.setContentType("application/json");
res.getWriter().write(array.toString());
}
}
-----------------------web.xml------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Test2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>cuServlet</servlet-name>
<servlet-class>com.jlcindia.ajax.CheckUnameServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cuServlet</servlet-name>
<url-pattern>/checkunm.jlc</url-pattern>
</servlet-mapping>
</web-app>
-- modified 23-May-17 7:24am.
|
|
|
|
|
sorry for the inconvinience plz help m out i reposted my question with proper formatt
|
|
|
|
|
No, you have just dumped the same totally unformatted code. Please stop doing this. Post only the code (enclosed within <pre>) that demonstrates your problem, as I already suggested. And please add a proper description of your problem.
|
|
|
|
|
Is there a compelling reason that you're developing for HTML4?
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
|
Hi,
I have two JSON objects:
JSON Object 1
[{
"date":
[
"date-value1",
"date-value2,
........ ,
"date-value729"
]
}]
JSON Object 2
{
"data": [
{
"body": [ "body1" ],
"link": "link1",
"title": [ "title1" ]
},
...........
{
"body": [ "body729" ],
"link": "link729",
"title": [ "title729" ]
}
]
}
How can I merge the properties of these 2 JSON objects and have the following example as an output for all 729 records of data:
{
"data": [
{
"body": [ "body1" ],
"link": "link1",
"title": [ "title1" ].
"date": "date1"
},
...........
{
"body": [ "body729" ],
"link": "link729",
"title": [ "title729" ]
"date": "date729"
}
]
}
Examples that I found online are mainly about merging two identical JSON objects.
Thank you in advance for your time and consideration.
|
|
|
|
|
I already answered this in the C# forum; please do not repost. And please make up your mid, is this C# or Javascript?
|
|
|
|
|
Let's look at the following code.
(function() {
var a = b = 5;
})();
console.log(b);
According to you, the output of the console output will look like?
|
|
|
|
|
If you do not know the answer, then either reread your reference guides, or run the code to see the results.
|
|
|
|
|
|
Press F12, go to Console window, enter that code there and press Enter. You will see the results yourself! I assure, that will be the correct answer, based on your browser's console.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
I want to write a effect like this.
But I don't know how to do it.
could somebody taught me? thanks a million!
image
modified 16-May-17 5:05am.
|
|
|
|
|
Here is an example:
function emailValidator(element, alertMsg){
var emailvalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(element.value.match(emailvalid))
{
return true;
}else{
alert(alertMsg);
element.focus();
return false;
}
}
element.focus() does not go back to the "Enter your email box" when a wrong email is enter, it goes to the next input box. Searched all over.
|
|
|
|
|
How is this function triggered?
You could try delaying the call to focus :
...
alert(alertMsg);
setTimeout(function(){ element.focus(); }, 100);
return false;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
Have a JSON file. Made it to work in IE 7 and 8. But need to make it work on IE 6.
Here is the script added.
var results = document.getElementById("apps");
var apps = new XMLHttpRequest();
apps.open("GET", "js/books.json", true);
apps.setRequestHeader("Content-type", "application/json", true);
apps.onreadystatechange = function() {
if (apps.readyState == 4 && apps.status == 200) {
var data = JSON.parse(apps.responseText);
results.innerHTML = "";
for (var app_content in data) {
content += data[app_content].authorname;
results.innerHTML += content;
}
}
For IE 7 and 8 have Added these reference files
Is there any way to make it work in IE 6.
Thanks
|
|
|
|
|
The native XMLHttpRequest object was first introduced in IE7.
If you need to support ancient browsers like IE6, then you'll need to fall-back to the ActiveX version:
var apps;
if (window.XMLHttpRequest) {
apps = new XMLHttpRequest();
}
else {
apps = new ActiveXObject("Microsoft.XMLHTTP");
}
Using XMLHttpRequest in IE6 - Web APIs | MDN[^]
Alternatively, use jQuery[^], which handles this sort of thing for you. But you'll need to stick to v1.12, since that was the last version that supported IE6 and IE7.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|