JSP Application - Server has not found matching request URI error
777287Mar 9 2012 — edited Mar 16 2012Running 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);
}
}