Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with method

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't we start with something you tried and thought would work?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or look up the concept of servlet filters.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And JSPs.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now would be the perfect time to learn all about servlet filters.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11944
212
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Farakh khan wrote:I tried a lot but invain. Kindly help me to correct this method

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...

Obviously you'd need to adapt it to your own environment.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic