0

So I am trying to create this web application that uses java and trying to connect the html to java via httpservlet As a trial I am just trying to get some sample data passed to and from the html to java and vise versa. The issue I am having is when I run the html form, which works fine and I try to press the search button after adding the values I want, it goes to the 404 Not Found page. I tried to make sure that the compiled servlet class file resides in its package structure in /WEB-INF/classes folder. I also have a package. I am using tomcat to build and compile the app but I am getting "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." when I try to run "http://localhost:8080/". I have tried using @WebServlet, "action" in html and adding a jsp file. I have included images of the folder structure, web page and error.

I have no idea what I am doing wrong, would really love some help##


##

Folder Structure

Error

Web page

Java

@WebServlet("/servlet")
public class page extends HttpServlet {

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) 
throws IOException {

String accountid = request.getParameter("Accountid");
String marketid = request.getParameter("Marketid");

response.setContentType("text/html");
PrintWriter writer = response.getWriter();

writer.println("<html>");
writer.println("<head>");
writer.println("<title> Incidents search result </title>");
writer.println("<head>");
writer.println("<body>");
writer.println("<h1>" + accountid + marketid + "</h1>");
writer.println("</body>");
writer.println("</html>");
}

HTML

<form name="getInput" action="${com.example.page.java}/servlet" method="post">
    <p>Account id: <input type="text" name="Accountid"></p>
    <p>Market id: <input type="text" name="Marketid"></p>
    <input type="submit" value="Submit">
 </form>

web.xml

 <?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_3_1.xsd"
     id="WebApp_ID" version="3.1"
 >

 <!-- Invoke 'Generate' action to add tags or functions -->

 <servlet>
    <servlet-name>Servlet</servlet-name>
    <servlet-class>com.example.page</servlet-class>
 </servlet>
 <servlet-mapping>
    <servlet-name>Servlet</servlet-name>
    <url-pattern>/servlet</url-pattern>
 </servlet-mapping>
 <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>getInputs.html</welcome-file>
 </welcome-file-list>


 </web-app>

jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Same as the html

Edit: I have tried using Servlet returns “HTTP Status 404 The requested resource (/servlet) is not available” but it didn't seem to work, as I have shown in the code and folder structure and am also using tomcat plus have tried all the different ways of writing 'action=...' in html.

Edit: This is the new error that I am getting New Error

s.matta
  • 21
  • 1
  • 3
  • Possible duplicate of [Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"](https://stackoverflow.com/questions/11731377/servlet-returns-http-status-404-the-requested-resource-servlet-is-not-availa) – Gatusko Jun 03 '19 at 13:59
  • @Gatusko have tried using Servlet returns “HTTP Status 404 The requested resource (/servlet) is not available” but it didn't seem to work, as I have shown in the code and folder structure and am also using tomcat plus have tried all the different ways of writing 'action=...' in html. – s.matta Jun 03 '19 at 15:13
  • by looking at your error image we can derive that you are hitting doGet method there cause parametres are passed in url but your code contains doPost method. are you using correct methos for state transfer ? – Onkar Musale Jun 04 '19 at 13:27

1 Answers1

0

I think the problem is with action path provided in HTML remove ${com.incidents.cashout.CurlExecutor.java} & try it might work. Find - out path by sysouts .

HS447
  • 81
  • 9