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

~s.o.s~ stands for a smart and cool universal savior with beautiful angel wings. ;-)

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

Look into the RandomAccessFile class. The only downside being the file is a treated as a sequence of bytes rather than the conventional line oriented view which many are used to. This class is especially for example useful when you want to come up with your custom file format which would have a fixed header size.

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

Will code for money; it doesn't matter whether it's C, C++, Java or C# as long it's a general purpose, fairly famous programming language. It's my job to churn out quality software which I think I am quite good at, though I must agree the language you program in greatly influences the way you look at things in terms of the initial requirement and the final outcome.

BTW, all the lady Java programmers I have seen either moved on to something simple like Testing or into Project Management. I guess Java is too much to handle for them. ;-)

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

> Is there a JavaScript api to look at methods? I googled and I didn't find anything familiar. I
> am used to the java api.

Look at the documentation provided by w3schools, Mozilla devleopment center and MSDN on Javascript.

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

Involving javascript for doing automatic number generation is the worst choice you could have made. Just allow a DAO class of that specific table handle the job of automatic number generation which would typically be exposed through some function like getNext().

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

Accessing the database from JSP which is meant for display / view purposes is a bad practice. Put all your database access code in a servlet which would then set the retrieved data in a session or request scoped variable which would then be accordingly rendered in the JSP file. Look into JSTL (JSP standard template library) for a clean demarcation between display and logic.

Coming to your problem at hand, one thing which you can do is to set the 'display' style property of the option element to none for the elements which you don't want to render. Something like:

<!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>
</head>
<body>
    <form action="#" id="frm">
      <select name="selPrimary">
        <option value="one">1</option>
        <option value="two" style="display: none;">2</option>
        <option value="three">3</option>
      </select>
    </form>
</body>
</html>

The obvious disadvantage of this approach is that your site won't function when javascript is disabled since you would be needing its help for toggling the display style property of option elements.

You would attach an event handler to the onchange event listener of the primary select box. Based on it's value, you would iterate through the options of the secondary select box and make then visible / invisible based on some mapping which you would be having (populate second select box with 1.1, 1.2, 1.3 if the value selected in the first select box is 1 etc.). If all this seems confusing, …

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

Which record are you talking about anyways? Please make an attempt to at least specify the exact nature of your problem as explicitly as possible instead of letting the one helping you out to do all the thinking.

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

An option would be to use the Java library iText to convert the given text to PDF which can be then written back to the browser. Generating image from text seems to be a pretty complicated task; something which I haven't personally tried out. Maybe this article will help you out.

I would personally go with the PDF approach.

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

> This my code which will refresh the page

Apart from being wrong on many counts, what kind of help do you need with this? It takes some kind of effort to convert an existing page into a page which uses Ajax. For this you need to learn Ajax, it's not something which someone can post for you.

Don't access database from a JSP. It's a view technology, so use it only for rendering. Keep the database accessing part restricted to servlets or EJB's if you are using them. When a item in the listbox is selected, fire a ajax request to a servlet with the value of the list item being passed to it. Inside the servlet, do you normal processing and just write the data you just fetched to the Servlet Output Stream. You can then access the result using the responseText property of the Ajax object in Javascript.

If all this seems to be alien to you, then you need to work with a few Ajax tutorials here and there to get a good grasp of how things work.

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

Of course, I don't know about others but at least my browser has some etiquette. ;-)

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

If you find a solution to a problem, it is recommended that you mark it as solved by clicking the Mark it as solved link, and if possible, posting the solution which worked for you. That way, someone else facing the problem who stumbles upon this thread might find your answer to be useful. I guess this is the least we all can do, can't we? :-)

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

Use the Apache commons upload library to ease the task of image uploading. Once you get hold of the image, store it in the database as a BLOB (Binary Large Object). and retrieve it back as a stream of bytes which can be used for recreating the image. Maybe this article will get things moving for you.

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

You need to use Ajax for it. There are many decent Ajax frameworks out there which you can use with a minimalistic knowledge of Javascript. Your query is by far too generic, post your code if you get stuck and we might be in a better position to help you out.

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

This post contains some useful information pertaining to your issue.

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

AFAIK, a session object is automatically created as soon as a request to a resource is made. In the Servlet API, you can get hold of the session object using request.getSession(), which grabs hold of the session for the current request. The way the session is maintained i.e. either by using cookies of session identifiers is generally not a concern for the developer though the latter is a much better solution. This might prove to be a good read.

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

Use the SimpleDateFormat class to parse the string into a Date object. Feed that Date object to the instance of the Calendar object and use it's function roll() to do the dirty work for you. Something along the lines of:

public class DateHelper {
    public static void main(String args[]) throws ParseException {
        String dateStr = "13/01/2008";
        SimpleDateFormat sdf = new SimpleDateFormat("DD/mm/yyyy");
        Date dt = sdf.parse(dateStr);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        cal.roll(Calendar.WEEK_OF_YEAR, 22);    //add 22 weeks
        Date newDt = cal.getTime();
        System.out.println("Training from " + dt + " to " + newDt);
    }
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You will have to cast it to the reference type you are expecting it to return. This is because the specifications say that getAttribute() returns a variable of type Object which of course makes sense since it enables us to store a reference variable of any kind. Maybe something along the lines of:

session.setAttribute("isLoggedIn", Boolean.TRUE);
Boolean b = (Boolean)session.getAttribute("isLoggedIn");
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

He is talking about those small images you have used in your navigation bar to let the users know it is a drop-down.

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

> <jsp:getProperty name="value" property="value" /> This means "get the 'value' property of a bean identified by the name 'value'", but there is no such bean in your case which goes by the name of 'value'. Maybe you wanted to do something like <jsp:getProperty name="example" property="value" /> ?

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

The thing you are trying to do is not recommended. Read this thread as a reference which discusses a similar issue.

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

> I know I'm probably being dumb here but I cannot seem to compile a java bean.

You are missing a static import in your package declaration. import static System.out;

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

Your problem seems to be this line in your JSP file:
> <%@ page import="mybeans.processFormBean" %> What exactly is processFormBean here? Is it a package? Are you trying to import all the classes from the processBean package? If yes, then you are doing it the wrong way. To import all the classes of a particular package, you need to do something like: <%@page import="mybeans.processFormBean.*" %> As a rule of thumb, *never* keep anything in your JDK/JRE installation directory. Create a separate lib folder for your application which will contain all the libraries specifically used by your applications. In case of a web application, this would be the lib directory inside WEB-INF. Also, the lib directory implicitly forms a part of your classpath so you don't have to explicitly set it anywhere.

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

Don't use statement, use PreparedStatement. Date can be stored database table using either java.sql.Date (only for dates) or java.sql.Timestamp (for date along with time). Read the JDBC tutorials for more details.

Also each SQL implementation (i.e. each database) has it's own specific way of generating the current date, so if you know you are going to stick to one implementation, you can make use of that feature. For e.g. with Oracle, it's sysdate. insert into mytable(name, lastAccessed) values('sos', sysdate);

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

> instead of accessing the images as collection items, use document.getElementById('imageID')

Actually it's the other way round. Instead of traversing the DOM tree it's better to use the images collection which holds a reference to all the images object in the document.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
public class FireFox {
    public static void main(String args[]) throws IOException {
        Runtime run = Runtime.getRuntime();
        String url = "http://localhost:8080/myservlet/";
        String ff = "your-path-to-firefox/firefox";
        String command = ff + " " + url;
        run.exec(command);
        System.exit(0);
    }
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This is because you have specified a relative URL and with you currently in the "shipper" context, it's trying to find "UploadUnconfirmedSOServlet" in that context. What you can do here is either make use of absolute URL's or adjust your relative URL to suit your needs. Something like:

<form name='uploadSO' method='post' action='../UploadUnConfirmedSOServlet'>
<!-- making use of relative URL -->
</form>

<form name='uploadSO' method='post' action='/myapp/UploadUnConfirmedSOServlet'>
<!-- making use of absolute URL -->
</form>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The == operator in case of references compares the references and not the values to which they refer. Since both id and key don't refer to the same string instance in memory, it always returns false. What you need here is to use the equals() method to do the same.

But seriously, this is the very basic of Java programming every programmer out there ought to know. I would recommend you go through the basic Java programming tutorials on the official Sun site before diving head first in J2EE.

oldestprofessional commented: Thanks! Your post helped me solve my silly mistakes too... +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> i got a problem while running a jsp file from one pc in another pc,that jsp file contains hyper
> link to another file

I am not very sure I understand what you want here but try http://hostNameOfAnotherMachine on the machine from which you want to access the host site i.e. from your machine. If it shows a tomcat welcome page, then it means you are successfully able to access the host machine in which case there seems to be a problem with your URL.

I feel you are missing the webapp name from your URL i.e. the URL should most probably look like http://someOtherHost/myWebApp/index.jsp

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

No, there isn't any direct method of doing the same. This is because the representation you are talking about is the way browser is configured to / coded to display XML; this would differ from browser to browser.

If you want to make this happen, you would have to create a XML document instance from the XML received as string and apply some Javascript magic to convert that in memory tree structure to something of value for the client using a bunch of <ul> and <li> and what not. This is by no means a simple task unless you are well versed in Javascript.

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

Looks a bit more sophisticated than the previous one and above all, it's usable, something which Dani was not planning to do at first. ;-)

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

Happy to help. :-)

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

What do you mean by doesn't work? Post a sample test case for which your code fails. And come to think of it:

Date EndDate = null; //get it from your db or log file...
Calendar cal_lastlogin = Calendar.getInstance();
if(cal_lastlogin.before(calExpired)) {
   /* something */
}

Here, you are pulling out the date to be compared in a variable EndDate and end up not using it. cal_lastlogin will always give a current Calendar instance, hence the test will be always false.

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

Glad I could point you in the right direction. :-)

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

You need to escape the XML strings returned and convert the <, > and other characters which have special meaning in HTML to their HTML entities.

< - &lt;
> - &gt;
" - &quot;

You can try something like:

String str = ab.result();
str = str.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> My advice to jbennet and other young fellows, don't heed the crude advice of iamthwee or
> his buddy josch. That kind of behaviour is disgusting, let them grab their own fat behinds, if
> they enjoy it so much.

Or be smart by acting the way ZZucker / Ene Uran recommend on the outside and being a beast like Josh and Iamthwee recommend on the inside. You get the best of both worlds and it works or at least used to work. ;-)

But seriously, I agree with ZZucker, girls are not sex objects though you would find many out there who hold great pride in being treated like a ****. There can't be anything worse than breaking the heart of a girl who loves you with her heart and soul. So in the end, it all depends on whether you want to play games or give it a honest try.

> Next thing will be SOS calling me a "pesky kid" to make my day!
I see that I have made quite an impact by posting in this forum. But seriously, act like a kid, be treated like one, age has got nothing to do with this.

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

The article Solving the logout problem at Javaworld seems to be a good read.

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

Yes, request.getParameter() always returns a string unless you plan on challenging the API.

As far as date is concerned, you can decide on a format which you would be expecting from your users. At the server side, pull the date values entered by the user as a string, try to parse that using the SimpleDateFormat class. If an exception is thrown, the user entered an invalid or unacceptable date; if no exception, then you would get a java.util.Date object which can be then converted to a java.sql.Date object which can then be persisted to a database.

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

> How do I pass parameters FROM the secondary JSP back the PRIMARY JSP not the other way
> around?
You can use session variables as common piggyback mechanism though I am not very sure what you mean by pass the parameters.

The entire process of including the JSP is just an abstraction for the developer. In the end, the client would be just served with a single HTML file (unless you are using Iframes/frames). When the user clicks on the link to modify the record, just call the first or the parent JSP and perform a check in the first JSP to see if the user wants to just view or modify the records.

But still there seems to be something wrong with your design. Are you by any chance accessing the database from the JSP. If yes, it's wrong and you shouldn't do that. If no, then why use two pages? JSP technology is meant to be a presentation layer technology and it's primary purpose is the formatting of the data which is processed in a servlet.

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

> It doesn't ever get that far. It returns the "Access denied error" on:

Are you trying to make cross domain calls? What kind of URL are you using in your call anyways? Does it belong to your domain?

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

Asking your question in the official YUI forum/newsgroup would be more beneficial IMO since almost everyone here uses his/her choice of Javascript library.

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

Is it February already? Damn...

joshSCH commented: Spammer!!! :P +12
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The Sussex data structure notes along with the explanation given here should suffice for the time being. Do look into the source code of the LinkedList class to get a better understanding of how things work under the hood.

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

You are welcome. :-)

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

Use the getStyles function to get the CSS property of an element. You would probably get the width of the element in pixels but that should work fine for you.

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

Try document.forms[0].elements['yourElementName'].focus() . Don't use document.all. It's not a standard property of the document object. And having a 1.8K line source file is bad in itself IMO.

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

Looks good except for the thing that you don't explicitly set the length of the string since it's a read only property and would have no effect. Instead set the value of the form element to an empty string. Something like els[i].value = '';

OmniX commented: Helped me continualy to get a solution, Thankyou. +1
~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

You shouldn't use scriptlets in your JSP file. They hamper readability, maintainability and re usability. Firing SQL queries / database access from JSP code is also bad in itself.

Create a simple HTML login form. Create a form bean. When the form is submitted, redirect to a controller servlet which pulls the form values and creates a form bean out of this. Set this bean in the session scope. Call the validate function on this bean.

If validation succeeds, pass the bean instance to a DAO class (Data Access Object) which can persist in into the database/any other persistent storage and destroy the bean from the session scope. If validation fails, pass a error bean / a list of error messages back to the same page. Use the bean stored in the session to restore the values which were correctly filled and display the contents of error bean / list.

Use JSTL for flow control and looping. Look into the JSTL Core tag. Though it might look intimidating at first, learning it would finally make your code clutter free and is an invaluable for a J2EE developer to have. Look into the J2EE tutorials at the Sun Official site.

~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().