Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

A href command not working

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 225
Spring Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does the code show up when you view the source for the page?
 
Suleman zia
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Sherrif. what do you mean by the code show up?
 
Suleman zia
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh you mean when i do the view source for my searchservlet page?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Suleman zia
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Suleman


There is no error in your code except in a method


indicated by ERROR: .And it working fine with satisfying your requirement.
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You're still ignoring exceptions.
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In both examples you show it looks as if the value of 'id' is empty.
 
Suleman zia
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well sorry. i am learning servlets and i am new to it. So will definitely check the documentation on livehttp.
 
reply
    Bookmark Topic Watch Topic
  • New Topic