Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to call a Servlet

Hi there,

I am new to Netweaver and I need to create a web-application based on JSP and Servlets. My project has got the following structure:

EAR-Project: Testproject

Webproject: ServletTest

- source: com.company.IndexServlet

public class IndexServlet extends HttpServlet{

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

PrintWriter pw = response.getWriter();

pw.println("<html><head>IndexServlet</head><body>Das ist der Text</body></html>");

}

}

- web.xml

<web-app>

<display-name>Testme</display-name>

<description>WEB APP description</description>

<servlet>

<servlet-name>IndexServlet</servlet-name>

<servlet-class>com.company.IndexServlet</servlet-class>

</servlet> <servlet>

<servlet-name>Index.jsp</servlet-name>

<jsp-file>/Index.jsp</jsp-file>

</servlet>

</web-app>

- webContent: Index.jsp

<%@ page language="java" %>

<html>

<head>

<title>

Title

</title>

</head>

<body>

<h1>

I am the index content

</h1>

<form name="formular" method="post" action="/IndexServlet">

<input type="submit" value="Go ..."/>

</form>

</body>

</html>

When I press the button in the jsp, I get a 404 error. Can someone help me to solve the problem? How do I call servlets by URL?

Thanks for help.

Regards,

Thomas

replied

You get a 404 [Not found] error when the resource requested can not be found on the server. The reason could be

1. The requested resource does not exist on the server.

2. The path requsted is incorrectly mapped with the actual resource.

In case of your servlet, the only reason I can see is the incorrect mapping of your servlet. You need to have the following tag in your web.xml for correct mapping.

<servlet-mapping>

<servlet-name>IndexServlet</servlet-name>

<url-pattern>/IndexServlet</url-pattern>

</servlet-mapping>

And in this case

<form name="formular" method="post" action="/IndexServlet">

must work.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question