Win a copy of Terraform in Action this week in the Cloud forum!

Ravi Sree

Ranch Hand
+ Follow
since Jan 24, 2010
Ravi likes ...
MySQL Database PHP Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ravi Sree

Dear All,

I dont know what happened but this and other Dojo examples which I tried seem to work now.

Regards,
Sree
7 years ago
I have been trying different examples on showing progress bar for file upload progress for couple of days.

Some of the different example were using libraries like Dojo,jQuery and just using plain AJAX with iframe method.

But unfortunately, however i try i'm not able to show the progressbar thingy at all although
the upload part is working good.

Following is the example with Dojo[dojo-release-1.0.3]

I'm using Servlet 2.5,commons fileupload libs, TomEE-plus-1.7. 0 & ant for building tool
in ubuntu 12.04 as the platform with firefox 32.

Here is the code (as it was in the site)

build.xml


web.xml


ProgressServlet.java


ProgressListener.java


TestServlet.java


If i choose a file of size 68MB, on page load the progressbar is seen
but stays at 0% all the time even after submttting the form.

On debugging, cant find error/bug here.

P.S This code can be seen CodeGuru: FileUpload Example

I cant find where I'm going wrong or is it some bug

Thanks in advance.

Sree
7 years ago

If you need to call a stored procedure, java.sql.CallableStatement is what you use & not PreparedStatement.

But then again why store procedure if could use PreparedStatement (while inserting/updating the record).

Is it long time after the insertion/updation that you need to fetch the auto-generated id..?

Specify the scenario and whatever you have tried fully.
Got it.

Since it is called by the derby engine itself, is it initialised already, right.?
Hi Rob,

I did what you suggested, but shouldn't each variable be initialised?
I once got an error saying 'Atleast one variable was left unintialised' or something...

Well, i did go a bit further than that after that.
Some of the changes i did were-


1. I used java.sql.Statement instead of PreparedStatement in preparing the query.
Since it is inside the backend that shouldn't harm any security principle, I hope.
2. Later on, i figured the reason for the problem -
I was closing the ResultSet in the finally block of Stored Procedure - out of habit
I commented that and only closed the Statement and Connection.
3. I was adding a ',' in the end and forgetting to remove it from the query.
Well I removed that.
4. Also I was calling and executeQuery() instead of execute() for calling the Stored Procedure
So, i replaced that too..



After all these analysis and repair I finally got it working..
I think if eventhough I was able to do it, coderanch being there is a great relief for many like me..

Sree
Why dont you post the table design too?
Try this and check:


I think this should work.
Hi All,

I have been trying my hand on stored procedures in derby(JavaDB 10.8) with an example for 2 days now.

I need to fetch some records from a table 'tbl_students' using it.
But i keep getting a NulPointerException, I cant figure out why.

This procedure takes mainly 2 parameters – pagenumber & maxRows, both as integers.

I created the stored procedure in derby using this:


I created the class and the method, compiled it and even packed it into a jar file properly without any error.

StudentStoredProcs.java


I created the database,table and even populated it data.
I installed the jar file(pagsortex.jar) without any error using this:


The class i wrote to call this stored procedure :
StudentStoredProcTest.java


The error trace i got is:


java sptest.StudentStoredProcTest
Connection established successfully!
SQL Error:The exception 'java.lang.NullPointerException' was thrown while evaluating an expression.
java.sql.SQLException: The exception 'java.lang.NullPointerException' was thrown while evaluating an expression.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedCallableStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeQuery(Unknown Source)
at sptest.StudentStoredProcTest.testIt(StudentStoredProcTest.java:22)
at sptest.StudentStoredProcTest.main(StudentStoredProcTest.java:58)
Caused by: java.sql.SQLException: The exception 'java.lang.NullPointerException' was thrown while evaluating an expression.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 13 more
Caused by: java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
... 10 more
Caused by: java.lang.NullPointerException
at derby.pagesortex.StudentStoredProcs.pageStudents(StudentStoredProcs.java:32)
at org.apache.derby.exe.acf81e0010x0142xc795x43dex00000167f4380.g0(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.derby.impl.services.reflect.ReflectMethod.invoke(Unknown Source)
at org.apache.derby.impl.sql.execute.CallStatementResultSet.open(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
... 6 more



Although I did this referring DerbySQLroutine-DB-derby-wiki, this code is mine for most of the part.
So, i know errors are bound to exist

Any input is greatly appreciated.
Sree

PS:I believe this logic may too have mistakes, do point out if that strikes you...
Hi,

Thanks Bear,
I did as you suggested and found that the error was mine.
Following where the changes that I did :-

1. Remove the <script> tags in ajax.js
2. Replace with xmlHttpRequest.setRequestHeader for xmlHttpRequest.setRequestHandler in ajax.js.
One of the major typo mistakes i did
3. I wrote to call doPost inside the same resulting a unwanted recurring loop, I meant to call the doPost from doGet.
4. Change the script type from text/javascript to javascript/text in index.jsp (I dont think it is much of a change though).

Thanks again, JavaRanch rocks

Regards,
Sree

Pat Farrell wrote:As others have said, just use HTTPS, that's what it was designed for. Its been used in production for well over a decade. Its a solved problem.

Now, if you want to increase system security and reliability, do not ever trust anything coming from the browser.



Got it Pat, Thanks

Regards,
Sree
10 years ago
Hi Madhan and Tim,

I totally understood your explanation.
I will look more into details in this topic.
Thanks.

Regards,
Sree
10 years ago
Hi All,

I tried a simple AJAX example I found on net.

Here are the files:

ajax.js


com.ajax.HelloWorld.java


index.jsp


web.xml


directory structure is:-

Ravi Sree wrote:
index.jsp
ajax.js
/src
|
com/ajax/HelloWorld.java
/WEB-INF
|
web.xml
/lib
/classes
|
com/ajax/HelloWorld.class



It is not working as expected, rather i unable to see any change.
On the click of the button in the bottom-left side of IE, an error message is displayed:-


Line : 10
Char : 1
Error: Object expected
Code : 0
URL: http://localhost:8080/AjaxHW/



I am using WinXP SP2, Jdk 1.6, Tomcat 5 and IE 7 for now.
I unable to figure out if I am missing something.
I will appreciate your opinions on this.

Regards,
Sree

Bear Bibeault wrote:You can encrypt values in the URL but not the complete URL. The context path and servlet path must be in clear text. No security issues are introduced by having these paths in clear text.



Thanks Bear,

I got your point.
Upon searching some security issues,
I found something like 'packet-sniffing', 'cross site request forgery', etc.
How can I prevent the requests to from such attacks (which is what I originally meant by improving security, )
Also can you put some light on what is 'Base64' encoding type & why is it used in real-life situations.

Regards,
Sree
10 years ago
Hi Bear,

By means of terms, yes i meant encrypting.

Regards,
Sree
10 years ago

Madhan Sundararajan Devaki wrote:In my opinion, instead of writing your own Framework (unless you are a Framework developer) you may use the popular frameworks such as Struts2 or Spring etc... to solve your business problems at the earliest. The popular frameworks also offer security and performance.



Hi Madhan,

Thanks for replying,

I agree to your point of "not-trying-to-reinvent-the-wheel",
and although I went through some of the framework codes,
i could not fully understand the flow details.

Here what i am really trying is get the thorough knowledge
by working up from the scratch.

I hope i am not being unreasonable.

Regards,
Sree
10 years ago
Hi All,

I am working on web project on using servlets, filters, jsp, JDBC, etc .
In this, I plan to use common Patterns like
Front Controller, Command, DAO, Abstract Factory, Factory etc.
So far I was able to design the model layer(bo, dao, dto layer).
Now, If the user wants to go the user's home page from a certain page,
the url as of now will be

./user/Home


which when encountered by the controller using the Command Pattern
will instantiate the action

com.abc.user.Home

to handle the request.

I feel this action url can be encoded for more security even without using https.

I am aware about the encodeUrl(String) which adds the sessionId to the url.
But is there anything more that can be done to ensure security.

I will appreciate your opinions regarding this.

Regards,
Sree

P.S. Please feel free to elaborate if i need to be more clear about my question.
10 years ago