~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> <%@ page language="java" %>
> <%@ page import="java.lang.*"%>
These two lines are not necessary. You don't need to specify the language. The package java.lang.* is implicitly imported, you don't need explicit import statements. This is the very basic of Java programming which every java programmer must be aware of.

> <font size=4 face="verdana" color="#112244>
Font tag is now deprecated. Use CSS instead.

> So what is going wrong?
The error is very clear. When debugging such types of problems, always look at the root cause which has triggered the entire exception chain. The root cause in your case is java.lang.NumberFormatException: null . This means your parseInt() method is getting a null which implies that either str1 or str2 is null .

You will now need to debug your code by either putting a lot of print statements or debugging using an IDE like Eclipse.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

And "Questions??", don't forget to use code tags the next time you post code which is preferably properly indented.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

From the Ecmascript specification:

The dollar sign ($) and the underscore (_) are permitted anywhere in an identifier. The dollar sign is intended for use only in mechanically generated code.

The $() function is not standard javascript and is used by most libraries to stand for the most commonly used function : getElementById().

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I am confused here, maybe you should paste the markup (HTML) next time so we have a clear view of what we are dealing with here.

Do you have a markup like this?

<input name="input[]">
<input name="input[]">

or like this?

<input name="input[0]">
<input name="input[1]">

If it's the latter, then what I have posted should work. You get hold of the first input element using document.forms[0].elements["input[0]"] . But if it's the former, there is no unique way of accessing the input element. That is possible only if you have an element with a unique id or a unique name. In that case, you do something like:

var els = document.getElementsByName("input[]"); // See this
for(var i = 0, max = els.length; i < max; ++i) {
  /* access the input elements using the index i. */
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Peter, the OP wanted to know how to check whether a JDK or a JRE path was provided during installation and not the environment variable PATH.

Ankita B, try running a simple servlet / jsp without using any beans and let us know if it works. The exception message clearly states it has got something to do with the classpath and it wasn't able to find the class you requested. Also you need to provide us the directory structure you are using, the problem is definitely at your end.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I can follow your code apart from the first line.

I am just stepping through the elements of the array using a loop and comparing each element with the user input. If it matches, then the user has entered a correct password. If all the elements have been tested without a match, then the password is incorrect.

If you still have trouble understanding the basic programming concepts, maybe you should start off with some basic programming / javascript tutorials, practice a lot and attempt your project once you are comfortable with those.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You need to iterate over the array and compare each array entry against the user input. Currently, you are comparing an array object with a string, hence the error.

for(var i = 0, max = arr.length; i < max; ++i) {
  var found = false;
  if(arr[i] == pwd) {
    found = true;
    break;
  }
}
if(found) {
  alert("Correct password");
} else {
  alert("Incorrect password");
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> javaAddict had the write idea

Write? ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> how can i check if the path provided was to jdk or jre?

Create a very simple/minimalistic JSP which just outputs "Hello World" or some other random text, and try to access your web application. If it doesn't compile, it means that the path supplied was of JRE and not JDK.

> control panel->system->advanced->environment variables->new->CLASSPATH-> . ;

You don't explicitly need to set the CLASSPATH that way, remove it. The Tomcat class loader automatically takes care of it and makes sure it loads all the classes present in the WEB-INF/classes folder. The directory structure needs to look something like:

webapps
|--- myapplication
      |--- jsp file
      |--- WEB-INF
             |--- web.xml  
             |--- classes
                   |--- foo
                         |--- Login.class

Also, don't use scriptlets in your code, use JSTL. And first and foremost, read a bit more about the basics of Servlets/JSP's from the link suggested by me in one of the other threads. There is no point in trying to program something without even knowing the basics of it.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Are you sure you provided the path to JDK instead of JRE during Tomcat installation? If yes, then paste your code (JSP along with Java files) and we will see what can be done.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Though it works, it's an incorrect way of doing things. location property of the window object is an object, not a string. The location object in turn has an href property of type string and hence location.href = "url"; is the correct, location = "url"; is not.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Is form_input the variable holding the form name or is it the form name? If it's the form name, you need to enclose it in double quotes. If it still doens't work, test the page in Firefox, look at the error console and let me know what it says.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Think of the include directive as a header file of languages like C/C++. When using the include directive, the combined contents of the original JSP page and all its included resources are translated into the same implementation servlet i.e. the contents of the included resource is copy pasted before translation to a servlet. The important thing here is that all this happens during translation time and only static content is supported.

The include action <jsp:include> is almost similar to the include directive except for a few subtle differences. The include action is executed at request time as opposed to translation time. Thus instead of the content of the include file being included in the calling JSP, the output of the JSP is included or passed to the JSPWriter of the calling page. This allows us to include both static and dynamic content into the JSP page. Using the jsp action also allows you to explicitly pass parameters to the included page.

<jsp:include page="/index.jsp">
  <jsp:param name="name" value="sos" />
</jsp:include>
sree22_happy commented: good answers +2
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If you want to access the value of input element "input[n]" try document.forms[formName].elements["input[n]"].value If you want the names of all the input elements, try:

function getInputNames(frm) {
  var arr = [];
  var elms = frm.getElementsByTagName("input");
  for(var i = 0, max = elms.length; i < max; ++i) {
    arr[i] = elms[i].name;
  }
  return(arr);
}

Read the Javascript FAQ for more details.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Never ever put business / backend logic in your JSP file. It's not what it was meant for. JSP is a presentation technology. Place your logic inside Servlets / EJB's and use DAO(Data Access Objects) to access your database. Reading the official J2EE tutorial would clear up things for you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I am a complete novice in java.
Then what you ought to do is start studying. J2EE 1.5 first cup and J2EE tutorials on the official Sun site should be sufficient at this point in time.

> I.m using oracle 9.1,tomcat 4.1 and java 1.4.1.
Why are you stuck with antiques when the latest version of Tomcat is 6 and JDK 5/6 stable version is very well available?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Of course, running a while loop till I get what I want or picking up elements based on their tag name is how I normally do things. I just wanted to let the OP know where he had made a mistake.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This is because the value which you receive in the upload box is a Windows specific path. IE would obviously know how to interpret it but Mozilla won't.

To make this possible, you have to convert your windows path into a file resource which can be used by all browsers using the file protocol. Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Expires" content="0" /> <!-- disable caching -->
    <title>Example</title>
    <script type="text/javascript">
    function getData(srci) {
        srci = srci.replace(/\\/g, "/");    /* convert all \ to / */
        encodeURI(srci);    /* encode the URI to enable escaping */
        srci = "file://" + srci;
        alert("File resource at : " + srci);
        document.images[0].src = srci;  
    }
    </script>
</head>
<body>
    <form action="#">
        <input type="file" onchange="getData(this.value);">
        <br><br>
        <image src="#" alt="image">
    </form>
</body>
</html>

Keep in mind that there is no such thign mentioned in the specification which says that the path to the local resource can be successfully retrieved from the file select control and hence even the above trick might not work in some browsers like Opera.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You have got to realize that when we talk of XML, the whitespaces in your document matter and they get counted as a "#text" node. Assuming that xmlObj has the reference of the root node of the document, something like alert(xmlObj.childNodes[1].firstChild.nodeValue); should do the trick.

Here:

xmlObj -> <code> (Element)
childNodes[0] -> Whitespace (Text Node)
childNodes[1] -> <name> (Element)
firstChild -> sree (Text node)
nodeValue -> sree

Assuming the XML file is:

<?xml version="1.0" standalone="yes"?>
<code>
    <name>sree</name>
</code>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> looks like that I'm complicating my life with this xml and javascript exercise but now this
> problem get hold of me and I want to sort it

Frankly I don't know what exactly are you trying to achieve here. It seems more like the case of using the wrong tools for the job here. Why bother with the complications involved with rendering XML using XSL and that too involving a hefty amount of Javascript. Debugging in your case will be nothing short of hell.

Coming back to the problem I don't think this is correct:

<xsl:for-each select="propertyList/property">
	<xsl:if test="id/num = 1">
    	<xsl:value-of select="general/bedrooms"/>Bedrooms,<xsl:value-of select="general/type"/>, <xsl:value-of select="general/tenure"/>
    </xsl:if>
</xsl:for-each>

If you try the code which I have fixed, you will see that clicking on the "div" opens up a new page. From this we can conclude that the XSL processing of the XML document is one pass and if you need any sort of dynamic behavior *after* the rendering is complete, you would have to resort to some other means. What you have done just won't work.

Here is something which works (in a broken sense, of course):

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Preview</title>

<style type="text/css">
table { width:800px; border:solid; border-bottom-style:groove; border-width:thick; border-color:#DCF3F5;border-collapse:collapse; margin-top:20px;}
td {padding-top:8px; padding-bottom:8px; padding-left: 10px; padding-right: 10px;}
th {padding-top:8px; padding-bottom:8px; padding-left: 10px;}
td.just {text-align:justify;}
td.empty {padding-top:0px; padding-bottom:0px; padding-left: 0px; padding-right: 0px;}
</style>

<script type="text/javascript">
    var DOMCapable = !!document.getElementById;
    var propertyNum = null; …
peter_budo commented: Thank you for going trough the mess of my code and helping me find the solution. +7
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The functions which I just posted would just output the value which was passed to them. So if propertyNum was "single" followed by a number, it would show the same. Did you try to alert the value of propertyNum by using window.alert(propertyNum) before using it?

Like I said, you need to paste the XML file which you are using for me to reproduce the problems you are facing.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Do you want to output the value of propertyNum once the <p> element is clicked? If so, then try this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Preview</title>
<script type="text/javascript">
    var DOMCapable = !!document.getElementById;
    var propertyNum = null;
    function show(property)
    {
        if(!DOMCapable) {
            return;
        }
        var grpStyle = document.getElementById("group").style;
        var sngStyle = document.getElementById("single").style;
        if(!grpStyle || !sngStyle) return;
        
        if(property == "group") {
            grpStyle.display = "block";
            grpStyle.visibility = "visible";
            sngStyle.display="none";
            sngStyle.visibility="hidden";
            propertyNum = "";
        } else {
            propertyNum = property;
            sngStyle.display = "block";
            sngStyle.visibility = "visible";
            grpStyle.display="none";
            grpStyle.visibility="hidden";					
		}
        var e = document.getElementById("txt");
        e.innerHTML = propertyNum;
        /*
        OR
        e.appendChild(document.createTextNode(String(propertyNum)));
        */
	}
</script>
</head>
<body>
<div id="group" onClick="show('single');">
<p style="cursor: pointer;">
    <xsl:attribute name="onclick">show('<xsl:value-of select='id/num'/>');</xsl:attribute>
    More details <xsl:value-of select='system/address1'/>
</p>
</div>
<div id="single" onclick="show('group');" style="display:none; visibility: hidden;">
<p id="propertyNum" name="propertyNum">Selected property ID is <span id="txt"></span></p>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Also it would be better if you create a style classes instead of changing individual style properties.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> <script type="text/javascript"> getPropertyNum();</script> This just means that you are executing the function getPropertyNum() and ignoring the return value, nothing else. To make sure the value is reflected in the DOM tree, you need to either do document.write(getPropertyNum()) (not recommended) or use the HTML DOM.

A few other things:

  • Don't use tabs for indentation, at least while pasting the code. It makes it harder to read the code. Use 2/4 spaces or use an IDE / Editor which can convert from tabs to spaces.
  • Also paste the accompanying XML file / response so that the people who want to help you out can try running the snippet without having to create their own test cases / sample input.

Revert back in case of more queries.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Internet Exploer does not like this method for some reason
Why? What made you reach that conclusion? In fact, my entire snippet for removing the selected option relies on removeChild and it works fine in IE/FF/Opera.

Also a few things to keep in mind.

  • Post the entire code which we can copy and run instead of just the relevant function which in turn requires us to develop a test case.
  • Don't use tabs for indentation, at least when posting code. It makes a mess out of it as you can very well see.

Here is a small snippet which should get you going:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Example</title>
    <script type="text/javascript">
    function doDelete(frm) {
        var sel = frm && frm.elements["selBox"];
        
        /* empty / non-existent select box */
        if(!sel || sel.selectedIndex < 0) {
            return;
        }
        var item = sel.options[sel.selectedIndex];
        var parent = item.parentNode;
        parent.removeChild(item);
        
        /* remove all the text nodes */
        while(parent.hasChildNodes()) {
            if(parent.childNodes[0].nodeType != 3) {
                /* non-text node found, exit the function */
                return; 
            }
            parent.removeChild(parent.childNodes[0]);
        }
        /* since we have reached here, the parent node
           must have zero elements so remove it */
        parent.parentNode.removeChild(parent);
    }
    </script>
</head>
<body>
    <form action="#" name="frm">
    <select name="selBox">
        <optgroup label="Swedish Cars">
        <option value ="volvo">Volvo</option>
        <option value ="saab">Saab</option>
        </optgroup>
        <optgroup label="German Cars">
        <option value ="mercedes">Mercedes</option>
        <option value ="audi">Audi</option>
        </optgroup>
    </select>
    <br>
    <input type="button" value="Delete Selected" onclick="doDelete(this.form);">
    </form>
</body>
</html>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Though I am not very clear as to what you mean, this snippet should give you a fair idea. If it doesn't, post your code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Example</title>
</head>
<body>
<script type="text/javascript">
    (function doSomething() 
    {
        while(true) {
            var ans = prompt("Enter either 1 or 2.");
            if(!ans || (ans != '1' && ans != '2')) {
                alert("You entered an invalid choice. Exitting...");
                break;
            }
            alert("You entered " + ans);
        }
    })();
</script>
</body>
</html>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Don't read the file character by character. Always make sure your the I/O operations performed by your program are buffered unless needed otherwise. The less the I/O calls, the better. Instead, read the entire line in a string using BufferedReader / Scanner class and perform the processing. Of the many ways in which the solution can be achieved, regular expressions and manual looping are two of them.

Using the regular expression approach, the regular expression would look something along the lines of: 'Mr. Jones "dog" and "cat" bosh'.match(/[^"]*"([^"]+)"[^"]*"([^"]+)"[^"]*/); This is Javascript, but the concept doesn't change and if you are familiar with regexes you should be able to convert it into a Java equivalent without much effort. If you are not comfortable with regexes, manual looping is the way to go.

Using manual looping, all you would have to do is look for quotes, set a flag, start collecting characters until you find a matching quote, reset the flag and continue the process. The matched data can be stored in a container like ArrayList.

I would personally go with the looping approach due to it's simplicity and extensibility. Plus if this is a homework problem, I am sure your professor would be expecting the looping approach rather than a classy regular expression solution.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Am I doing something wrong or am i totally incompetent?
You are probably asking this question in the wrong forum. This question has no longer remained a Javascript one since you have been successfully able to send the JSON encoded string to the server.

The way you decode the string on the server is purely dependent on your server side language of choice. Try asking this question in the C# or VB .NET forums of Daniweb.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> when I open my pages using ip (and not host name) thier javascript functions and events
> don't fire.
You mean http://xxx.xxx.xxx.xxx:8080/webapp/test.html over http://hostname:8080/webapp/test.html ?

> can any one help?
Use firefox to run your web app and look at the error console. (Tools -> Error Console)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use any C# JSON binding library which converts from JSON objects to C# objects and vice versa. The bottom section of the JSON home page has a lot of bindings for the C# language. LitJSON is one of those libraries you can use.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Paste only the relevant and indented code. Sifting through 50+ lines of unindented code is more of a bother.

As far as your problem is concerned, I don't see any name attribute assigned to your form elements and the algorithm I posted uses element names.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes, using Firefox as your development browser along with some useful plugins like Web Development and Firebug, you can cut down a lot on your development time.

And it doesn't depend on the IDE, really. It's more about experience and observation. I pinned down the problem the moment I saw those weird quotes. And you should be aware and quite competent with the IDE. In the screenshot I am posting, compare the two statements, one which has the weird quotes and the one which has the right kind of quotes. Don't you see a highlighting difference?

And which Eclipse are you using by the way? For web development using Java, you should be using WTP instead of the normal version which is not HTML/CSS/JS aware.

PS: > Edit: SOS, you beat me by a minute
And that too with a well indented code. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> XMLHttpRequestObject = new ActiveXObject(“Microsoft.XMLHTTP”);

If this is how your code looks in your Text Editor / IDE, you need to change the special character ” to double quotes ("). Avoid copy / pasting the code from your ebook into the editor since it might introduce such special characters.

A sample working snippet:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Expires" content="0"> <!-- disable caching -->
    <title>Ajax Example</title>
    <script type="text/javascript" src="ajax.js"></script>
    <script type="text/javascript">
        function getXmlHttpRequest() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            /*@cc_on @*/ 
            /*@if (@_jscript_version >= 5)
            try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                    return null;
                }
            } @end @*/ 
        }
        else {
            return null;
        }
    }
    function getData(datasource, target) {
        var xhr = getXmlHttpRequest();
        xhr.open("GET", datasource, true);
        xhr.onreadystatechange = function() {
            if(xhr.readyState == 4) {
                if(xhr.status == 200) {
                    document.getElementById(target).innerHTML = xhr.responseText;
                }
                else {
                    alert("Some problem occured);
                }
            }
        }
        xhr.send(null);
    }
    </script>
</head>
<body>
<form id="frm" name="frm" action="#">   
<div id="frmContainer">
    <div id="tgt"></div>
    <p></p>
    <input type="button" onclick="getData('data.txt', 'tgt');" value="Get Data">
</div>
</form>
</body>
</html>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

And if you still want to know a bit more about this thing, this blog post is does a good job of doing that.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> returnValue= true; This sets the value of the global variable returnValue to true and has got nothing to do with your issue.

> e.returnValue = true; This sets the return value of the event to ' true ' and is a MS only property. So your onclick returns false if the validation fails and thereby prevents form submission.

> e.preventDefault() This cancels / prevents the default action caused by the event. In our case, the click action submits the form which is prevented by calling p reventDefault(). It is important to notice that both e.returnValue = false; and e.preventDefault() in our case achieve the same purpose(of cancelling the forum submission) for different browser types.

OmniX commented: Very helpful information =) +1
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> An alternative approach to using a return statement is to set the "event.returnValue" to false:
...which would only work in IE.

In IE the event generated becomes a event property of the window object whereas in Gecko based browsers it is passed as a first argument to the event listener. A better approach would be:

function handle(e) {
	var e = e || window.event;
	if(!confirm("Do you want to continue?")) {
		if(e.preventDefault) {
			e.preventDefault();
		}
		else {
			e.returnValue = false;
		}
	}
}

<!-- more code -->

<input type="submit" onclick="handle(event);" />
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Try something like:

/**
 * Alerts out the selected item values of a select box
 *
 * @author sos
 * @param {HTMLFormElement} frm The reference to the form element
 * @param {String} name The name of the select box
 */
function show(frm, name) {
  var selOpts = frm.elements[name].options;
  for(var i = 0, max = selOpts.length; i < max; ++i) {
    if(selOpts[i].selected) {
      alert("Selected Item: " + selOpts[i].value);
    }
  }
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Sounds good in theory, right? But let me explain.

Ever wondered why the 'Tutorial Section' of Daniweb is so thin as compared to the 'Code Snippets Section'? This is because submitting a tutorial requires Davey's approval. That's right, that's not something even a moderator or super moderator can approve.

Plus approval takes effort and expertise. Ever seen the articles submitted at professional sites? The subject matter of such articles is approved only after being read and re-read by professionals in that field. In short, it takes a certain amount of money and time to get such things done.

Now compare this with Daniweb. Here every moderator / super-moderator (I can't say the same about Admins and Staff Writers) is doing a free service to the community by doing his moderation duties. Asking them to proof read the articles submitted by Daniweb members / non-members and judging their credibility would be a bit too much to ask.

Of course Dani can employ people to make sure that the articles confirm with the standard but that takes money. Professionals are not cheap to hire and when I say that I really mean they are *expensive*.

Also consider a situation in which a C article has to approved. The C forum has around 6-7 moderators. So wouldn't it make sense to get the approval of the majority to avoid conflict? But then again it brings us to the problem of getting a *majority* of moderators to read and …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> why not make a section on Wikipedia itself and have a link to it?
Sounds like a good idea.

But allowing everyone to contribute would be like making a big mess out of it, not to mention it would stain the name of Daniweb in general, and choosing you would have the right to contribute would not be a trivial task.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Glad you could get it to work. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Try downloading IE2, iCab (a browser), Opera 3 or Netscape 4 since these browsers are known to not support IFrames. Try downloading one of these and testing your page on it. But seriously, this is a dumb test since I am sure everyone must have moved with the times and has stopped using browsers from the stone age.

If you still continue with the test, let me know which browser works for your test.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> What i wanted was if the user wont have the Iframe support he may be provided with a web
> link so that he can click on it

So keep the link as a part of the content of the iframe tag.

<iframe src="somesource.html" name="frm" id="frm">
  <a href="somesource.html">
    Click here since your browser doesn't support IFRAMES
  </a>
</iframe>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

One way would be to try to create an IFRAME element using Javascript. If that fails, you can be sure that the browser doesn't support IFRAMES. But this requires your user to have javascript enabled.

var e = document.createElement("iframe");
if(!e)
    alert("Your browser doesn't support IFRAMES");

Another way to notify your users would be to place the message between the IFRAME tag. Something like:

<iframe id="iFrm" name="iFrm" src="Source.html">
Your browser doesn' support IFRAMES
</iframe>

But it is pretty much a moot point since all modern browsers support IFRAMES.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Creating a secure form has got nothing to do with Javascript. The javascript used under normal scenarios for enhancing the user experience and is client side only. In order to create a form whose data would be sent over a secure connection, you need to look into a protocol named as SSL (Secure Socket Layer).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> double word;
> print(word); //print unsorted array
> Arrays.sort(word); //sort the array
> print(word); //print sorted array

What are these things doing outside a method? Why is 'word' of type double and why is it declared as member variable of the servlet class which in itself lends to poor design since it would be shared by all your clients? What kind of an array do you want to sort -- an array of numbers or an array of strings? Nowhere in your markup (html file) do you provide the provision for accepting multiple values. You either need to provide such a provision or ask the user to enter values separated by some delimiter, for instance, a comma.

Assuming that you are trying to sort an array of strings provided by the user as comma separated values, you need to do something like this:

public class Sorting extends HttpServlet
{
    public void doGet(HttpServletRequest request,
         HttpServletResponse response)
            throws IOException, ServletException
    {        
        String word = request.getParameter("word");
        word = process(word);
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Sorting Servlet</title>");
        out.println("</head>");                  
        out.println("<body>");
        out.println(word);
        out.println("</body>");
        out.println("</html>");
    }
    
    public void doPost(HttpServletRequest request,
       HttpServletResponse response)
             throws IOException, ServletException
    {
      doGet(request, response);
    }

    public String process(String word) {
        StringBuilder buf = new StringBuilder(512);
        if(word != null && word.trim().length() != 0) {
            String arr[] = word.replaceAll("\\s+", "").split(",");
            Arrays.sort(arr);
            for(String str : arr) {
                buf.append(str).append("<br>");
            }
        }
        else {
            buf.append("<br>").append("No input supplied").append("<br>");
        }
        return(buf.toString());
    }
}

Having said all this, it's not a good …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There is either a problem with your markup or the way you are using / including Javascript. Did you try the snippet pasted by me in the above post? Did it work for you?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Did you include the 'json2.js' script at the top of your page? It must be the only reason or it has got something to do with your HTML file since stringify() works for me.

<html>
<head>
<title>Forms</title>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript">
function somename() {
    var o = objectify();
    var jsonString = JSON.stringify(o);
    alert(jsonString);
}

function objectify() {
    var o = {};
    var frms = document.forms;
    var formID = 1;
    var id = 1;
    
    for (i = 0, maxI = frms.length; i < maxI ; i++) {
        if (frms[i].name == 'form' + formID) {
            var frm = frms[i];
            var elms = frm.elements;
            var tmp = {};
            
            for (var j = 0, maxJ = elms.length; j < maxJ; j++) {
                var el = elms[j];
                tmp[el.name] = el.value;
            }
            o[frm.name] = tmp;
            formID++;
        }
    }
    return (o);
}
</script>
</head>
<body id="bdy">
    <form name="form1" action="#">
    <input name = "txtOne" value = "Text box one" />
    <input name = "txtTwo" value = "Text box two" />
    <input name = "txtThree" value = "Text box three" />
    </form>

    <form name="form2" action="#">
    <input name = "txtOne" value = "Text box one" />
    <input name = "txtTwo" value = "Text box two" />
    <input name = "txtThree" value = "Text box three" />
    </form>

    <form name="form3" action="#">
    <input name = "txtOne" value = "Text box one" />
    <input name = "txtTwo" value = "Text box two" />
    <input name = "txtThree" value = "Text box three" />
    </form>
<script>somename();</script>
</body>
</html>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> But what happens when those students want to work in a development background
Maybe start experimenting on their own instead of waiting someone to hold their hand and guide them in darkness?

> degrees do not mean much anymore here in UK
They don't mean much anyways unless they mean something to the student. Many students have the misconception that just by _passing_ the exams or _getting_ a degree will make them a good _XYZ_. One should seek clarity, experiment and enjoy ones work and one would never feel that their degrees / education don't mean anything.

The force is within you, let there be light. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Netbeans and Eclipse are the two dominant free ones out there which I normally use.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Here is a crude snippet:

<html>
<head>
	<title>Forms</title>

	<script type="text/javascript">
	function objectify() {
		var o = {};
		var frms = document.forms;

		/* loop through all the form objects */
		for(var i = 0, maxI = frms.length; i < maxI; ++i) {
			var frm = frms[i];
			var elms = frm.elements;
			var tmp = {};
			/* loop through all the form elements of each form */
			for(var j = 0, maxJ = elms.length; j < maxJ; ++j) {
				var el = elms[j];
				switch(el.type) {
					case "textarea":
					case "text":
						tmp[el.name] = el.value;
						break;
					default:
						/* add custom behavior for other form elements */
						break;
				}
			}
			o[frm.name] = tmp;
		}
		return(o);
	}
	</script>
</head>
<body id="bdy">
	<form name="frmOne" action="#">
		<input name = "txtOne" value = "Text box one" />
		<input name = "txtTwo" value = "Text box two" />
		<input name = "txtThree" value = "Text box three" />
	</form>

	<form name="frmTwo" action="#">
		<input name = "txtOne" value = "Text box one" />
		<input name = "txtTwo" value = "Text box two" />
		<input name = "txtThree" value = "Text box three" />
	</form>

	<form name="frmThree" action="#">
		<input name = "txtOne" value = "Text box one" />
		<input name = "txtTwo" value = "Text box two" />
		<input name = "txtThree" value = "Text box three" />
	</form>
</body>
</html>

Just pass the object returned by objectify function to a function which returns the json string representation of a javascript object.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You need to attach an event listener to the onkeypress event handler of the form element which would monitor the key strokes and submit the form as soon as a RETURN key is pressed.

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>	
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>OK</title>
	<script type="text/javascript">

	function checkSubmit(e) {
		e = e || window.event;
		var code = e.keyCode || e.which;
		if(code == 13 /* return key pressed */) {
			var src = e.srcElement || e.target;
			if(!!src && !!src.form)
				src.form.submit();
		}			
	}
	</script>
</head>
<body id="bodyMain">
	<form action="/action.do" method="get" onkeypress="checkSubmit(event);">
		<select name="sel" multiple="multiple">
			<option value="one">1</option>
			<option value="two">2</option>
			<option value="three">3</option>
		</select>
		<textarea name="txtArea"></textarea>
		<input type="text" id="txtId" value="OK" />
		<input type="text" name="txtName" value="txtName" />
		<input type="button" value="Submit" />
	</form>
</body>
</html>