aspose file tools*
The moose likes Servlets and the fly likes A href command not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "A href command not working" Watch "A href command not working" New topic
Author

A href command not working

Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
i have a text box and a submit button. once a user enters the name and click on the submit button that user info is displayed in the table which is firstname, lastname, username and password. Now in that table i have a link to deleteservlet by the name of delete and updateservlet by the name of update. For some reason my update and delete is not showing in the table any idea?.



this statement is not executing. Thanks for any help.



SCJP 1.5
Baseet Ahmed
Ranch Hand

Joined: Dec 18, 2006
Posts: 224
Hi,

Can you tell us what error message are you getting(stack trace of error)
while running your application.






***********************************
Tip: Modesty is all virtue.
***********************************
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
No there is no error. My page is running good in tomcat. I can enter a name in the textbox and click on submit button and that person information is displayed in the table. The only problem i am having is that i cannot see the links for update and delete right beside the information of the user in the table. so then if a user wants to click on update it should go to my updateservlet page and a form is displayed, same thing goes for deleteServlet also.

My <A href> thing is not working. Since the id is a primary key and auto incremented i would like to show the id number also when a user clicks on delete or update.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

does the code show up when you view the source for the page?
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
Sorry Sherrif. what do you mean by the code show up?
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
oh you mean when i do the view source for my searchservlet page?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42649
    
  65
This may or may not have anything to do with the problem, but this:
catch (SQLException e) {
}
catch (Exception e) {
}

is not a good idea. How will you ever know that there was a problem?

What does the HTML look like that gets generated?


Ping & DNS - my free Android networking tools app
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
this is when i load my searchservlet page



and this is how it looks like when the information is displayed.



But there is no error. i was just trying to create a url beside the information table for each user so he have an option to update or delete. But for some reason its not showing. i think the problem is in this statement. i need to have variable id in order to recognize which id was deleted from my database.



[code]
Rajnish Ojha
Greenhorn

Joined: Jun 05, 2007
Posts: 1
Hi Suleman


There is no error in your code except in a method


indicated by ERROR: .And it working fine with satisfying your requirement.
Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi Suleman,

Hope this helps, look at your code:
String id = rs.getString(1); //gets FirstName
String id = rs.getString(2); //gets LastName
String id = rs.getString(3); //gets UserName
String id = rs.getString(4); //gets Password
String id = rs.getString(5); //gets ??

I think your last line will throw SQLException, but you swallow those (don't do that).
So better remove that line.

Herman
PS Your servlet is all in one: model, view and controller.
That's usually considered as bad, hard to test etc.
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
rangish my method for encodedhtml is running fine. i have tested in other applications also.

Herman hmmmm. Ok for instance in my sql i have a table by the name of USERS.posts which contains



There is a specific id for each user. in my URL for deleteservlet i would like to pass ID numebr also, so we know which user was deleted. now if i do this



Now it does not display any information + does not display the links also.
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
Now if i remove my String = id; and do this



it works fine. perfect no problem. so now my question is when a user clicks on delete it is suppose to delete the requested information. with no variable id how can i do that? this is my deleteservlet



Thanks for the help
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
ID seems perfect so for the time being just to make the program work i updated my sql to delete the record based on the first name of the user.



Sorry i am new to sql. but it still displays me the else statement part which says "error in details" and this is what i see on my url when i click on delete

http://localhost:8080/chapter4/DeleteServlet?firstName=

That means firstName is null. if its null then no record will be deleted. hope i make sense. sorry
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42649
    
  65


You're still ignoring exceptions.
Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi there,

-sql-parameters start at 1 ("rs.getString(0)" won't work), but since you swallow your sql-exceptions, you won't know (like Ulf said).

-rs.getString(2) will retrieve the 2nd column in your sql-statement
(which maybe the same column as in your table, but that depends on your sql-statement)

-try this:



and



Herman
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
ok thanks herman. i figured that post_id part earlier. Now everything works fine except when i click on delete my else statement always executes in deleteservlet.



if i use this statement


the stack trace prints


Now if i do this



i get this



my sql statement looks fine.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42649
    
  65
In both examples you show it looks as if the value of 'id' is empty.
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
yes exactly bartender. but i printed the post_id on my searchpage, so i can see all the id, username, firstname, lastname and password. for some reason when i pass that id to my deletservlet page it seems like id was never read or id was empty when it was passed to deleteservlet.

I debugged it for a long time still not successful. i think i can do this by having the option of deleting by the user firstName but still its not relevant and not a good idea to delete through the firstname, who knows there might be bunch of people with the same firstName.

Any ideas ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42649
    
  65
yes exactly bartender.

My name is Ulf.

I'd suggest to make sure that the correct id is submitted by the browser (using a tool like the LiveHTTPHeaders Firefox extension), and that it gets to the server (by looking at the access logs).
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
Well sorry. i am learning servlets and i am new to it. So will definitely check the documentation on livehttp.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A href command not working