Alvin John Niravukalayil :
When i try to run the code in eclipse it won't pass the arguments. please check the below images url.
But when i individually run the html code it passes the values.
I don't know why this work like this. My Servlet code is
package com.example;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AddServelet extends HttpServlet
{
public void services(HttpServletRequest req, HttpServletResponse resp) {
int i = Integer.parseInt(req.getParameter("num1"));
int j = Integer.parseInt(req.getParameter("num2"));
int k = i+j;
System.out.println(k);
}
}
and my web.xml code is
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>com.example.AddServelet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/add</url-pattern>
</servlet-mapping>
</web-app>
my html code
<html>
<body>
<form action="add">
Number 1: <input type="number" name="num1"><br>
Number 2: <input type="number" name="num2"><br>
<input type="submit">
</form>
</body>
</html>
Can anyone please help me with this. Thank you in advance.
pero_hero :
override the HttpServlet
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
method if you want to handle a GET request
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=403673&siteId=1