-1

I have designed a simple servlet, but it not working Instead of executing, it is getting downloaded through browser window.

When i execute the code, the HTML page runs OK, but after I submit form data the servlet gets downloaded as shown without servlet execution..

I tried so many times modifying the code and also searched I did not find this anywhere, so any help is appreciated

Please see the screenshots I have attached:

Image1(https://i.stack.imgur.com/YWXzp.jpg) Image2(https://i.stack.imgur.com/WMCwc.jpg)

//CLASS file
package com.pkg;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@WebServlet("/SltClass")
public class SltClass extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

        response.setContentType("HTML/text");

        String userNameVar = request.getParameter("userName");
           String passWordVar = request.getParameter("passWord");

           PrintWriter out = response.getWriter();

           out.println("hello user :" +userNameVar);   

    }}

HTML

    </head>
    <body>
        <div>TODO write content</div>

        <form action="Welcome" method="post">
            <input type="text" name="userName" />
               <input type="text" name="passWord" />

                  <input type="submit" value="Submit it" />


        </form>



    </body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
            <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

                <welcome-file-list>
                    <welcome-file>index.html</welcome-file>
                </welcome-file-list>    

                   <servlet>
                    <servlet-name>Sname</servlet-name>
                    <servlet-class>com.pkg.SltClass</servlet-class>
                </servlet>
                <servlet-mapping>
                    <servlet-name>Sname</servlet-name>
                    <url-pattern>/Welcome</url-pattern>
                </servlet-mapping>
                <session-config>
                    <session-timeout>
                        30
                    </session-timeout>
                </session-config>
            </web-app>
M4ver1k
  • 1,505
  • 1
  • 15
  • 26
user2929
  • 21
  • 6
  • Starting GlassFish Server 4.1.1 GlassFish Server Open Source Edition 4.1.1 (build 1) is already running and responding on administrator port GlassFish Server 4.1.1 is running. Incrementally deploying SltClassMe Completed incremental distribution of SltClassMe Incrementally redeploying SltClassMe run-deploy: Browsing: http://localhost:8080/SltClassMe run-display-browser: run: BUILD SUCCESSFUL (total time: 0 seconds) – user2929 Jan 12 '16 at 12:50

1 Answers1

0

Could you see if switching text with html makes any difference - like this:

response.setContentType("text/html");
Ludwig S
  • 551
  • 3
  • 8
  • I have been trying so many times... i dont know what is error... now working PERFECTLY..thank you.. – user2929 Jan 12 '16 at 12:51