Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF example Weird result - help please

 
Carol Bloch
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working my way through the examples in HF Servlets and JSPs. I am in chapter 3 trying to run the first version of the controller servlet. The servlet compiles fine and I deploy it to the coorect older in the deployment structure. I restart tomcat and hit submit on the form that calls this servlet. This version of the servlet is supposed to get a parameter from the form and display it back on a html page. Instead I get a pop-up asking if I want to download a file. The filename is the name action on the html form. Any clues why this might happen or where to look. I have looked at both the code in the form and the code in the servlet and it looks ok.

Here is my form code:
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the enctype of your form ? (ENCTYPE="multipart/form-data")
 
Carol Bloch
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,
Here is the form:
<html><body>
<h1 align="center">Beer Selection Page</h1>
<form method="POST" action="SelectBeer.do">Select beer characteristics<p>
Color:
<select name="color" size="1">
<option>light
<option>amber
<option>brown
<option>dark
</select>
<br><br>
<center>
<input type="submit">
</center>
</form></body></html>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your form seems ok. It works for me.
Did you check your web.xml ?

In your servlet did you use setContentType ?
--> setContentType("text/html")
[ December 20, 2005: Message edited by: Satou kurinosuke ]
 
Carol Bloch
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do set the content to Text/html.
Here is my servlet code:
package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class BeerSelect extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException{
response.setContentType("text.html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
String c = request.getParameter("color");
out.println("<br>Got Beer color " + c);
}
}
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read text.html here, not text/html. Plz confirm
 
Carol Bloch
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did have text.html instead of text/html. It is the little mistakes that are so hard to spot. Thank you for taking the time to help.

Carol
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic