0

I am currently using Eclipse and Tomcat for my servers and I am trying to make a method that passes an input string as output onto the HTML website.

I got some help from the question below, but how would I go about implementing the code from that link into a servlet file?

How to create a Restful web service with input parameters?

If anyone has any other solutions to taking text, passing it to the method and outputting it I'd appreciate it.

The code I'm using is a demo for Hello World (scroll to the very bottom):

https://www.ibm.com/developerworks/library/os-eclipse-tomcat/index.html

CheeseFerrari
  • 57
  • 1
  • 7

3 Answers3

0

For your requirement you can develop a servlet which can accept any input as request parameters and in servlet you can manipulate that information as per your requirements. Then you can create the HTML inside servlet (although not preferred way, you can use jsp for this) to display anything.

Har Krishan
  • 273
  • 1
  • 11
0

Just configure the servlet referred through the link you provided like:

<servlet>
  <servlet-name>HelloServlet</servlet-name>
  <servlet-class>
     com.example.servlets.HelloServlet 
  </servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>HelloServlet</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

Once you hit the servlet through browser it will display Hello World on the HTML page. As said you can pass any parameters to this servlet and then can manipulate, display those in HTML output.

Har Krishan
  • 273
  • 1
  • 11
0

suppose this is your html form

<form action="login" method="get">
        <table>
            <tr>
                <td>User</td>
                <td><input name="user" /></td>
            </tr>
            <tr>
                <td>password</td>
                <td><input name="password" /></td>
            </tr>
        </table>
        <input type="submit" />
    </form>

Then to get the parameters of this form in your method you should use the getParameter method of HttpServletRequest object.

protected void doGet(HttpServletRequest request, HttpServletResponse response,String inputString) 
          throws ServletException, IOException {
          String userName = request.getParameter("user");
          String password = request.getParameter("password");
          response.getWriter().write("Name = " +userName+ " And Password = " +password);
            }
SwapnilKumbhar
  • 347
  • 2
  • 5
  • 17