File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Problem with method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with method" Watch "Problem with method" New topic
Author

Problem with method

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
I am writing the following code in each and every class but want to create a method that do the same thing to get me rid off of writting each time in every class. I tried a lot but failed



Can anybody please help me?

Thanks in anticipation

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

Why don't we start with something you tried and thought would work?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Or look up the concept of servlet filters.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And JSPs.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
Thanks for your favorable replies. Appreciated!

I tried a lot but invain. Kindly help me to correct this method

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Correct it by getting rid of it. Authentication checking of this type should be done in a filter that you write and declare once.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
Bear Bibeault wrote:Correct it by getting rid of it. Authentication checking of this type should be done in a filter that you write and declare once.


Thanks for your prompt reply

I am totally not aware of filters and use to with methods.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Now would be the perfect time to learn all about servlet filters.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11279
    
  59

Filters can work on the data coming into your web application, or on the data leaving your web application. As such they can be used for such things that are common to all your code such as security on the way in, and setting the correct header information on the way out (although there are often better ways to do the later).

I would recommend a good book on developing for the web, such as Head First Servlets and JSP. Failing that, you might want to look at the Sun Java Servlet Technology tutorial, or a specific article on The Essentials of Filters.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
Andrew Monkhouse wrote:Filters can work on the data coming into your web application, or on the data leaving your web application. As such they can be used for such things that are common to all your code such as security on the way in, and setting the correct header information on the way out (although there are often better ways to do the later).

I would recommend a good book on developing for the web, such as Head First Servlets and JSP. Failing that, you might want to look at the Sun Java Servlet Technology tutorial, or a specific article on The Essentials of Filters.


Thanks for recomending tutorials and books but can you please solve my real problem right now as the project is in my hand and I have to deliver it within a few days. I believe the methods are still workable in java servlet but certainly will start with recomended books/tutorials

Thanks again & best regards
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Farakh khan wrote:I tried a lot but invain. Kindly help me to correct this method

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
David Newton wrote:
Farakh khan wrote:I tried a lot but invain. Kindly help me to correct this method



Wow! great! Appreciated!!

Thanks from the bottom of my heart and yes Thanks also to recommend some tutorials regarding filters. I started to studied them

Best Regards
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
Farakh khan wrote:
David Newton wrote:
Farakh khan wrote:I tried a lot but invain. Kindly help me to correct this method



BUMP!!

Error:
Cannot find symbol:
-- Attributes
-- StringUtils

Shall I have to import some packages?

I tested by imorting java.util.* but not works

Please help me again. copy paste what am doing



Best Regards
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

Obviously you'd need to adapt it to your own environment.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
David Newton wrote:...

Obviously you'd need to adapt it to your own environment.


I not understand completely. Can you please be more specific?

Thanks again & best regards
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Nobody here is going to write your code for you. I showed you one way to fix your method, including using a constant to define the attribute name, and using a third-party library to do the null/empty check. To be honest, I expected the code I wrote to be self-explanatory--I'm kind of at a loss to explain it any further without doing *all* your work for you, which is something we really try not to do here.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
David Newton wrote:Nobody here is going to write your code for you. I showed you one way to fix your method, including using a constant to define the attribute name, and using a third-party library to do the null/empty check. To be honest, I expected the code I wrote to be self-explanatory--I'm kind of at a loss to explain it any further without doing *all* your work for you, which is something we really try not to do here.

I am really thankful for you as you at least tried to help. Appreciated!

Its throwing compile time error not runtime or logical errors

Anyhow working with it and if I succeeded will let you know

Thanks again
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I wrote the method the way *I* would have written it (well, with the caveat that this isn't how I'd do it). Obviously since I'm writing it the way *I* would write it I used the techniques and libraries *I* would use. You're not using them. So replace the stuff that you *don't* have with the stuff you *do*. It's really clear what the intent of the code I used is, or at least it *should* be.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
David Newton wrote:I wrote the method the way *I* would have written it (well, with the caveat that this isn't how I'd do it). Obviously since I'm writing it the way *I* would write it I used the techniques and libraries *I* would use. You're not using them. So replace the stuff that you *don't* have with the stuff you *do*. It's really clear what the intent of the code I used is, or at least it *should* be.


Thanks again for guidance. Will let you know about the progress soon

Appreciated
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with method
 
Similar Threads
Another newbie JSF question on user authentication
Constructor Problem
Problem regarding redirected error message
Problem With jsp:forward
Refcursor value is invalid, Bigger type length than Maximum, Protocol violation