Newbie to IntelliJ problem with two page JSP app

Answered

Hi,

This code is running in Eclipse but when I give it a try in IntellIJ, the index.jsp page is presented as expected (in Tomcat 9.0.27) but the login.jsp page seems to not be found and I'm getting an HTTP 404 error and "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."

I'm building to a WAR file with index.jsp in web folder and login.jsp in WEB-INF folder.

Any help is appreciated!

index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>SQL Injection demo using J2EE JSP</title>
</head>
<body>
<form method="post" action="login.jsp">
<center>
<table border="2" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2">SQL Injection demo using J2EE JSP (Enter "ABC123/ABC123" or "ABC123' or '1'='1' --")</th>
</tr>
</thead>
<tbody>
<tr>
<td>User Name</td>
<td><input type="text" name="username" value="" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>

 

login.jsp
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="com.example.util.DBUtil"%>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
Connection con = DBUtil.getMySqlConnection();
Statement st = con.createStatement();
ResultSet rs;
String query = "SELECT * FROM HR.employee WHERE username='" + username + "' and password='" + password + "'";
System.out.println("Query executed: " + query);
rs = st.executeQuery(query);
out.println("Data for: "+username+" follows: ");
while (rs.next()) {
session.setAttribute("username", username);
out.println(rs.getString("first_name") + " " +
rs.getString("last_name") + " (" +
rs.getString("username") + ")\r\n");
}
%>

 

0
3 comments

Hello,

Is it possible to share full project example?

0

Douglas,

Sorry, seems there is some problem with link. I got 404.

0

Please sign in to leave a comment.