aspose file tools*
The moose likes Servlets and the fly likes Unable to display result in web browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unable to display result in web browser" Watch "Unable to display result in web browser" New topic
Author

Unable to display result in web browser

Vijaya Bhaskar
Greenhorn

Joined: Sep 02, 2008
Posts: 19
Hi dear all,
I need a help that when I am invoking a servlet class file from my HTML file instead of displaying output in my browser it is downloading my output as a file..Why it is?..

thanks


Bhajji
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Perhaps showing us some code could help?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vijaya Bhaskar
Greenhorn

Joined: Sep 02, 2008
Posts: 19
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class FirstServlet extends HttpServlet {


public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException{
res.setContentType("html\text");
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("hi vijay");
out.println("</body>");
out.println("</html>");
}
}

...........................................................
Home.html

<html>

<body BGCOLOR="GREEN">
<FORM name="f1" action="./first" method="GET">
Enter name:<input type="text" name="uname">
<input type="submit" value="click">
</form>
</body>
</html>
...................................................................
web.xml

<web-app>
<servlet>
<servlet-name>First</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>First</servlet-name>
<url-pattern>/first</url-pattern>
</servlet-mapping>
</web-app>
sat khar
Greenhorn

Joined: Nov 13, 2013
Posts: 1
changing content type to

should resolve the issue
Vijaya Bhaskar
Greenhorn

Joined: Sep 02, 2008
Posts: 19
Sorry, I did it but I am getting the same problem..
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 914
    
  13

There are errors in your web.xml and in your servlet. Start here and read about the types of paths and relative links to correct your web.xml. Then put your servlet in a package. Never use the default of no package.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
 
wood burning stoves
 
subject: Unable to display result in web browser