This discussion is archived
11 Replies Latest reply: Mar 16, 2012 1:18 PM by 777287 RSS

JSP Application - Server has not found matching request URI error

777287 Newbie
Currently Being Moderated
Running Win Server 2008 64 bit. Using JDev Studio Edition Version 11.1.1.5.0.

I'm writing a test application which gives the user an interface to write custom queries. The application cosists of two Java classes, a jsp page and web.xml. I run the application on the integrated WLS in J dev. The jsp page displays fine, but when I press the <EXECUTE> button I get ' Error 404--Not Found - The server has not found anything matching the Request-URI' . Any advice would be greatly appreciated. Following is the contents of the application:


<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<servlet>
<servlet-name>SqlGatewayServlet</servlet-name>
<servlet-class>mmv2.SqlGatewayServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SqlGatewayServlet</servlet-name>
<url-pattern>sqlGateway</url-pattern>
</servlet-mapping>


</web-app>


----------------------------------------------------------------------------------
qtest.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>qtest</title>
</head>
<body>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:if test="${sqlStatement == null}">
<c:set var="sqlStatement" value="select * from User" />
</c:if>
<h1> manaar SQL Gateway </h1>
<p> Enter a SQL statement and press the execute button <br>
</p>

<p>
<b> SQL Statement: </b><br>
<form action="sqlGateway" method="post">
<textarea name="sqlStatement" cols="60" rows="8">${sqlStatement}
</textarea> <br> <br>
<input type="submit" value="Execute">
</form>
</p>
<p> SQL Result:</br> </br>
${sqlResult}
</p>
</body>
</html>


</body>
</html>

---------------------------------------------------------------------------------------------------------



package mmv2;


import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

import java.sql.*;


public class SqlGatewayServlet extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String sqlStatement = request.getParameter("sqlStatement");
String sqlResult = "";

try {
// get a connection
String dbURL = "jdbc:mysql://<server>/*******";
String username = "root";
String password = "**********";
Connection connection =
DriverManager.getConnection(dbURL, username, password);

// create a statement
Statement statement = connection.createStatement();

// parse the SQL string
sqlStatement = sqlStatement.trim();
if (sqlStatement.length() >= 6) {
String sqlType = sqlStatement.substring(0, 6);
if (sqlType.equalsIgnoreCase("select")) {
// create the HTML for the result set
ResultSet resultSet = statement.executeQuery(sqlStatement);
sqlResult = SQLUtil.getHtmlTable(resultSet);
resultSet.close();
} else {
int i = statement.executeUpdate(sqlStatement);
if (i == 0) // a DDL statement
sqlResult = "The statement executed successfully.";
else // an INSERT, UPDATE, or DELETE statement
sqlResult =
"The statement executed successfully.<br>" +
i + " row(s) affected.";
}
}
statement.close();
connection.close();
} catch (SQLException e) {
sqlResult =
"Error executing the SQL statement: <br>" + e.getMessage();
}

HttpSession session = request.getSession();
session.setAttribute("sqlResult", sqlResult);
session.setAttribute("sqlStatement", sqlStatement);

String url = "/sql_gateway.jsp";
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
}
  • 1. Re: JSP Application - Server has not found matching request URI error
    DrClap Expert
    Currently Being Moderated
    You're using a page-relative URL in your form, which is always risky. What is the actual URL which the browser tries to connect to when you press the Execute button?

    And I must say this question would be better off in the JSP forum.
  • 2. Re: JSP Application - Server has not found matching request URI error
    777287 Newbie
    Currently Being Moderated
    It routes to the sqlGateway URL when I execute. So what's the alternative to using a page-relative URL??

    Would appreciate your answers and I will also report in the JSP forum. Many thanks!
  • 3. Re: JSP Application - Server has not found matching request URI error
    DrClap Expert
    Currently Being Moderated
    Jay wrote:
    It routes to the sqlGateway URL when I execute.
    That was a lot less specific than what I expected. Let me ask again what URL the browser went to, without forcing me to make any assumptions.
    So what's the alternative to using a page-relative URL??
    Well, here's a link to a document which explains that better than the one-line answer I had in mind: http://www.coderanch.com/how-to/java/RelativeLinks.
  • 4. Re: JSP Application - Server has not found matching request URI error
    777287 Newbie
    Currently Being Moderated
    Apologies for the general info.

    The URL is:

    http://127.0.0.1:7101/MantraMar2012-Project1-context-root/sqlGateway

    Also I read the article. I tried an absolute path and a getContxt method both of which produced the same error.

    Finally, this may seem like a sillly question but I can't seem to find the JSP forum so I re-posted in the Jdev and ADF forum but would really appreciate any guidance about where the JSP forum is. Thanks!

    Edited by: Jay on Mar 9, 2012 4:26 PM

    Edited by: Jay on Mar 9, 2012 4:27 PM
  • 5. Re: JSP Application - Server has not found matching request URI error
    777287 Newbie
    Currently Being Moderated
    Well I found the JSP forum, posted my question and waiting an answer. I also provided the URL which my application routes to when pressing the EXECUTE button. Pls let me know if this is enough info. Thanks!
  • 6. Re: JSP Application - Server has not found matching request URI error
    777287 Newbie
    Currently Being Moderated
    Just to re-confirm. I read the article, provided you with the specific URL and re-posted this on the JSP forum. Still no answer. Would appreciate if you have any further suggestions as to an alternative path i can use. Thanks!
  • 7. Re: JSP Application - Server has not found matching request URI error
    gimbal2 Guru
    Currently Being Moderated
    Jay wrote:
    Just to re-confirm. I read the article, provided you with the specific URL and re-posted this on the JSP forum. Still no answer. Would appreciate if you have any further suggestions as to an alternative path i can use. Thanks!
    What an odd thing to say. You'd think you have stopped looking for the cause of your problem and are now just waiting and waiting and waiting...


    I'm a fool, but I like to keep it simple. You get a 404 on a servlet resource. Okay, what can cause that?

    - the url is wrong (from what you've posted I don't see any issues)
    - the servlet is not deployed at all
    - you are deploying to entirely the wrong server instance (not as silly a suggestion as you may think)

    So. Can you prove that the servlet is actually deployed, on the server that is listening at localhost:7101?
  • 8. Re: JSP Application - Server has not found matching request URI error
    777287 Newbie
    Currently Being Moderated
    You'd think so wouldn't you? Fortunately I'm not stupid enough to rely on answers from any single source :-)

    The servlet is only being run using the Integrated WLS in Jdev and has not been deployed to any stand alone environment.

    I'm actually just running the qtest.jsp, so are you saying that I have to actually deploy the servlet to the Integrated WLS? Or should i deploy to a stand alone instance?

    I am currently going through some ducumentation (namely http://docs.oracle.com/cd/E24382_01/user.1112/e17455/deploying_apps.htm) to look into deployment on the Intergrated serve.

    I deployed the app as a war file on the integrated server using a different context root:

    http://127.0.0.1:7101/MantTest/qtest.jsp

    The structure of the deployed War is as follows:


    WEB-INF/classes/m15/SQLUtil.class     
    WEB-INF/classes/m15/SqlGatewayServlet.class     
    WEB-INF/lib/jstl.jar     
    WEB-INF/lib/standard.jar     
    WEB-INF/web.xml     
    WEB-INF/weblogic.xml     
    error.jsp     
    qtest.jsp     
    sqlGateway.jsp     


    As usual i first run qtest.jsp (http://127.0.0.1:7101/MantTest/qtest.jsp), press execute and get error 404 with the following (URL: http://127.0.0.1:7101/MantTest/sqlGateway)

    Are there any known issues with deployment on the Integrated WLS? Do you see any mistakes with the way I have deployed the app? Many thanks!

    Edited by: Jay on Mar 16, 2012 4:51 AM
  • 9. Re: JSP Application - Server has not found matching request URI error
    gimbal2 Guru
    Currently Being Moderated
    Jay wrote:
    WEB-INF/classes/m15/SqlGatewayServlet.class     
    Oh...
    <servlet-class>mmv2.SqlGatewayServlet</servlet-class>
    Really?
    Are there any known issues with deployment on the Integrated WLS?
    Stop thinking like that. Its not the tool, its you. Always. if you automatically assume that, finding the root of problems all of a sudden becomes a whole lot less troublesome.
  • 10. Re: JSP Application - Server has not found matching request URI error
    777287 Newbie
    Currently Being Moderated
    I'm sure it's me, but the web.xml now looks like this (when getting error 404), so it references the m15 package:

    <?xml version = '1.0' encoding = 'windows-1252'?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">

    <welcome-file-list>
    <welcome-file>/qtest.jsp</welcome-file>
    </welcome-file-list>


    <servlet>
    <servlet-name>SqlGatewayServlet</servlet-name>
    <servlet-class>m15.SqlGatewayServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>SqlGatewayServlet</servlet-name>
    <url-pattern>/sqlGateway</url-pattern>
    </servlet-mapping>



    </web-app>

    Edited by: Jay on Mar 16, 2012 5:30 AM
  • 11. Re: JSP Application - Server has not found matching request URI error
    777287 Newbie
    Currently Being Moderated
    SO I also tried to deploy this on Tomcat and get the following error:

    ManTomcatMar2012/sql_gateway.jsp

    description The requested resource (/ManTomcatMar2012/sql_gateway.jsp) is not available.

    for some reason Tomcat is expecting to find a jsp file called sql_gateway.jsp, but the web.xml file was not changed at all since the same WAR was deployed to the Tomcat.

    This is obviously a deployment issue so are there are any additional configurations I should be making (either to the web.xml or other files) that will point the server towards the correct servlet?

    Thanks!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points