This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes Constructor Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

Constructor Problem

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 672




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

Joined: Mar 15, 2009
Posts: 452

A servlet must have a no-arg constructor.

avi sinha


SCJP 5.0 SCWCD 5.0
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 672
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

Joined: Mar 15, 2009
Posts: 452

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

Joined: Mar 15, 2009
Posts: 452

also give some information about the servlet or jsp from where you are trying to call this servlet.

avi sinha
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 672
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

Joined: Jan 10, 2002
Posts: 56540
    
  14

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?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452

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

Joined: Mar 22, 2008
Posts: 672
Appreciated!!

Thanks from the bottom of my heart
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452

Farakh khan wrote:Appreciated!!

Thanks from the bottom of my heart


you're welcome

avi sinha
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 672

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

Joined: Mar 15, 2009
Posts: 452

sorry a cast is needed here my mistake.

write

avi sinha
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 672
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

Joined: Mar 15, 2009
Posts: 452

please post the complete code of your servlets then may be we can identify what the problem is ??

avi sinha
Charles 'King
Ranch Hand

Joined: Jul 05, 2009
Posts: 56

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

Joined: Jan 10, 2002
Posts: 56540
    
  14

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

Joined: Mar 22, 2008
Posts: 672
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

Joined: Jan 10, 2002
Posts: 56540
    
  14

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

Joined: Mar 22, 2008
Posts: 672
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

Joined: Jan 10, 2002
Posts: 56540
    
  14

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

Joined: Mar 22, 2008
Posts: 672
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

Joined: Mar 22, 2008
Posts: 672
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Constructor Problem
 
Similar Threads
Want to convert my code in method
validation problem using jsp,servlets,ms-access db
Date Comparison in Java
user validation page
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection