Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to display result in web browser

 
Vijaya Bhaskar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps showing us some code could help?
 
Vijaya Bhaskar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changing content type to

should resolve the issue
 
Vijaya Bhaskar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I did it but I am getting the same problem..
 
J. Kevin Robbins
Bartender
Posts: 1725
19
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic