Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying the servlet from the servlet

 
rekha devan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two files, one is the HTML file that prompts the user to enter some text in the textfield. When the user enters the text and clicks the submit button. A servlet is invoked to display the length of the servlet. Now after displaying the length, the servlet should prompt the user again to enter text.

Now what I am doing is I have a servlet to display the length and again below it I display a textbox prompting the user to enter text and then Submit button.When the user click on submit I invoke the same servlet again. When I try to invoke the servlet it gives 404 error.

What i wanted to know is

1. Is my logic right?
2. why is it giving 404 error?
3. If the logic is wrong what is the right way to do it?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should separate the "getting the length" logic,
and the "display the length" logic.

I think that you should get the length in the servlet,
put it in the response,
and redirect the response to a JSP file, containing the textfield.

JSP --submit-> Servlet --redirect--> JSP -- and so on -> ....

Do you have to stick to HTML, or can you use JSP instead ?
 
rekha devan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No i don't need to stick to HTML, I am just practicing.

But is it not possible to do

html->servlet->html->servlet.............?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you can. But I would not recommend using it to display dynamic content

Ok, let's go back to your 404 problem.
Can you post the action of your form ?
<form action="...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic