| Author |
HF example Weird result - help please
|
Carol Bloch
Greenhorn
Joined: Nov 21, 2005
Posts: 18
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
|
Did you set the enctype of your form ? (ENCTYPE="multipart/form-data")
|
[My Blog]
All roads lead to JavaRanch
|
 |
Carol Bloch
Greenhorn
Joined: Nov 21, 2005
Posts: 18
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
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
Joined: Nov 21, 2005
Posts: 18
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
I read text.html here, not text/html. Plz confirm
|
 |
Carol Bloch
Greenhorn
Joined: Nov 21, 2005
Posts: 18
|
|
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
|
 |
 |
|
|
subject: HF example Weird result - help please
|
|
|