Bookmark Topic Watch Topic
  • New Topic

Constructor Problem

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator




My Login.java
=============


I am trying to pass referer to my Login.java. The browser is displaying following error:


Thanks in anticipation

 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
A servlet must have a no-arg constructor.

avi sinha
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator
avi sinha wrote:A servlet must have a no-arg constructor.

avi sinha


What you suggest in case of my problem. I mean I want to pass referer to Login.java

Thanks for your prompt reply
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
the way you are moving on here is not correct. you are treating your servlet class like a plain java class . a servlet will work only if it is being called by the container.

keep this in mind:

a servlet class becomes a servlet when the container calls the init(ServletConfig) method of the servlet by passing ServletConfig object .

avi sinha
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
also give some information about the servlet or jsp from where you are trying to call this servlet.

avi sinha
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator
avi sinha wrote:also give some information about the servlet or jsp from where you are trying to call this servlet.

avi sinha


I provided this in first part of my question

Thanks again
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Do not declare constructors for Servlets. Use the init() method to initialize a servlet.

Also, please indent your code properly.

Also, servlets should not have instance variables.

What are you actually trying to accomplish?
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
ok i got it .

create mapping in the DD for the second servlet .
for ex : /serv2

now your first servlet should be

but i think you will have to change a lot of code. its better to start from scratch for these two servlets and you should keep your business logic outside the servlet.
create a java file for database related works and call it from the servlet

avi sinha
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator
Appreciated!!

Thanks from the bottom of my heart
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Farakh khan wrote:Appreciated!!

Thanks from the bottom of my heart


you're welcome

avi sinha
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator

String referer=req.getHeader("Referer");


what I did is:


but this will display the referer in iFrame and will not break the frame. The problem will still exist

Best Regards
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
sorry a cast is needed here my mistake.

write

avi sinha
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator
avi sinha wrote:sorry a cast is needed here my mistake.

write

avi sinha


I am thankful for your favorable replies



OUTPUT:
=======
null


My Servlet-2
==============


OUTPUT:
=======
referer=null


Best Regards
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
please post the complete code of your servlets then may be we can identify what the problem is ??

avi sinha
 
Charles 'King
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
The referer isnt a mandatory field and usually only available if the client sends it - if the request originates from a link or resource. Direct requests do not contain a referrer. The referer field can be stripped from the HTTP header by a proxy or firewall. Session and request scoped attributes are a better solution.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Even after all these posts, I still have no good idea what is trying to be accomplished. And yes, relying upon the unreliable "referer" probably dooms it to failure.

Perhaps the actual goal might be posted at some point?
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thankful to all professionals who helped me and beared me

Actually the origional problem is this that I have an iFrame in all pages of the website that have source (/servlet/User). This servlet checks that if the user logged in successfully then displaying control panel else displaying html static contents to log in with action /servlet/Login

Login.java matches the login/pass from db and if ok then redirect to /servlet/User

Now the problem is this that when am redirecting any file then it displayed in iFrame instead of main page and I am unable to redirect my user from where they are comming

Thanks again
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
So what does all that have to do with the referer? It's like saying "My car won't start, so I decide to trim this tree over here."

If you want to make something happen in the parent, you'll need to include script in your iframe response to trigger behavior in the parent.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear Bibeault wrote:So what does all that have to do with the referer? It's like saying "My car won't start, so I decide to trim this tree over here."

If you want to make something happen in the parent, you'll need to include script in your iframe response to trigger behavior in the parent.


Thanks for your reply

You mean javascript? or something in java servlet?

Best Regards
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
JavaScript. There is nothing you can do on the server to affect the behavior of anything outside of the window/iframe that the response is being sent to.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear Bibeault wrote:JavaScript. There is nothing you can do on the server to affect the behavior of anything outside of the window/iframe that the response is being sent to.


Thanks for your favorable reply

I tried a lot java scripts but as I am not good in Javascripts, unable to write. Can you help me to guide little bit

Thanks again & best regards
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear Bibeault wrote:JavaScript. There is nothing you can do on the server to affect the behavior of anything outside of the window/iframe that the response is being sent to.


I posted this problem http://www.coderanch.com/t/474517/Servlets/java/Java-with-Java-Script for getting any help regarding javascript that is in my mind but yet not get any response

Thanks again & best regards
 
    Bookmark Topic Watch Topic
  • New Topic