This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line!
See this thread for details.

Alok Kushwah

Ranch Hand
+ Follow
since Jul 10, 2007
Merit badge: grant badges
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Alok Kushwah

In Employee class Images should be declared as




You can save byte array as blob in database and retrieve the data in back in array.

But to serve image to browser, you cannot use this VO|DTO directly, you have to create a new servlet to server binary image data. Use URL of servlet in <img> tag.
16 years ago
Its null because code is trying to poll empty queue in last iteration. Poll() return null in case queue is empty.

Dry run your code will find out why its returning null in loop.

For hint you did following code before the loop. which removes one element from queue.

Then loops runs ai length times and before last iteration queue is exhausted.
Looks like program is trying to insert rows with same id. You can see "Unique Key Voilation" error in thread. Query the database table and you can find out row exist or not.
Here one website is working as client to otherwebsite.

Solution 1:

Here HTTP website (application C) is client of HTTPS website (application S).

application C have to use httpClient (http://hc.apache.org/httpclient-3.x/) and submit the request to application S. you can use POST method also.

***************************************************

Solution 2:

I will go forward and say your HTTPS website is exposing webservice.

Expose webservice from application S. User web service client in apllication C to consume the webservice.
16 years ago
If scenario is as follows

- browser send request for some resource and wait for response.
- If browser get the response within x seconds display the resource.
- If browser does not get the response within x seconds display the timeout message.

Solution:

1. Open the page/resource in frame/iframe or use ajax
2. Use javascript function setTimeout("declare_timeout()",5000) for waiting for resource to download.
3. in declare_timeout() javascript function change url of frame/iframe to timeout page.
4. To clear the timout after page/source dowload use clearTimeout().

Notes: you can check some condition in step 3 to check dowload is completed before decalring timeout.

resource: http://www.w3schools.com/js/js_timing.asp
16 years ago
I am just curious. Are you going to implement login using javascript? In this implementation user can see the source of page and see what user name and password should be enter.

1. If you want to copy data as soon as you connect flash drive to system

- Read about Autorun in windows. Autorun.ini file can be at root where you can specify program to run.

[autorun]
OPEN=SAMPLE\AUTORUN\AUTORUN.EXE
ICON=SAMPLE\AUTORUN\WIN98CD.ICO


2. If you want copy all data from from flash drive you have to use file/direcory copy command

copy | xcopy etc you can also write your own program

By the way this is not the right forum to ask this question. Its for EJB and other JEE technologies. Whatever I suggested is my wild guess.




16 years ago
Please see my previous comment about uploading, processing, Saving and then serving uploaded documents.

To include html or static text you can use following server side jsp tag

<jsp:include page="{relativeURL | <%= expression %>}" flush="true|false" />

I already talked about inframes etc other ways of displaying these text.
However you cannot use static include in this case <%@include%>

To include image use following HTML tag

<img src=<%=expression%>/>

(You can create a servlet like "getContentFile.do?fileKey=abcshsajsd" to access the uploaded file from anywhere.)

16 years ago
Do you want include the images generated by client program or some HTML files? Including images is very differnt then including text content in JSP. Are you uploading image files and want to show them in JSP?
16 years ago
If I got it correct, you want make user able to upload the content to the site. Content would be visble to user in some website (may be same website also).

My suggestions

1. Security
- To avoid cross site script don't allow javascript in uploading HTML. You have to parse the whole stream for it ans strip off unwanted tag and javascript code.
- Don't allow user to use iframe or layer which allows to show other sites conatent in your site.
- Put the file in the place where it would not be accessible directly. Like DB or outside context folder or inside web-inf. But in case if you want access through iframe, it must be accessible from browser. See second point for iframe solution. This is to prevent user to upload JSP and execute it.

2. For effeciency
- To increase the seconday memory uitilization compress the file at server side. In this case you have to decompress the file to server it back.
- To increase the serving time you can keep the file in file system and include it at server end in case file.
- Iframe is good solution only in case uploaded file is somehow accessible directly from browser. You can create a servlet like "getContentFile.do?fileKey=abcshsajsd" to access the uploaded file from anywhere.
16 years ago
Both EJB and Java bean contains "Bean" in their name, however they are not replaceable by each other. EJB technology is to develop distributed server side component/service, on other hand Java Bean is a simple class with accessor methods for its attributes (setter/getter) (As you said POJO). EJBs are not POJO. Read about <html:form> tag. tag should work with Java Bean (POJO).
Simple answer to your question is - to implement asynchronous use case.

When ever client of a service don't want to wait for completing of the call is the example of asynchronous case. Queue is used in most of the solutions. Only resposibilty of client is to put one message in the queue. Client can go ahead without worring about how, when, who will process the message.

MDB is always the consumer of that queue. MDB never be called like session or entity bean directly by client. MDB is called by container whenever there is message in the destination queue for the consumpation.

I will give you one simple example. Invetory managment system may have MDB litening to low invetory queue. Order Managmenet system may write to the queue in case inventory for perticular product falling below some level.

You can find examples @ http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/MDB.html
Scope of bean is application context scope, so try to get it from application not from request. To get it from application use ServletContext.
16 years ago
EJB spec says that enterprise bean must not attempt to listen on a socket, so no server socket is allowed in EJB. But you can open client socket to connect to server socket. However socket must be closed when the ejb is passivated. Socket connection must be established when the ejb is activated.

I will suggets avoid opening any type of socket in EJB.
There may be 1000 or more user session active at a given time but not all need DB connection at same time. If any user action requires connection to DB, thead request to pool for connection and complete the work and return the connection to pool as soon as possible. In case no connection is available Connection pool manager will try to make new connetions to DB to fullfill the request. If connection count reaches to max count, requester can wait in queue for some time for connection to be released by some theads. It may timedout after some time and thread will get no connetion available or timed out exception.

Pooling is a trick to manage/share expensive resource. It helps in sharing resource among lots of users. EJB use object pooling in same way. A big family can share two bathrooms. There is no problem if no more than two family members need them at same time. If any memeber needs it and both bathroom is in use, that person have to wait until one is free. There would be exception in case waiting time is too long. But everything would be fine if family member try to minimize the time spent in bathroom to keep them free as much as possible. It would be very costly to make one bathroom for each memeber

So its important to use these type of resorces carefully. Request connection when you are ready for DB trasaction after all calculations and processing on data is done. Return/close the connection as soon as you are done. Don't wait for garbage collection to close it.

Last thing ..if DB server allows 25 connection max than there is no way more than 25 connection made. But through pooling they can be shared by thousand users.
16 years ago