1

I have written a simple code in JSP but it is showing error. I have imported the ojdbc7/14 in library. I am using Glassfish server 4 and I had to change the http port of oracle database. The following program is not working. Can anyone tell me the reason?

<%@ page import="java.sql.*" %>

<HTML>
<HEAD>
<TITLE>Simple JSP to Oracle connection Example</TITLE>
</HEAD>
<BODY>
<%
Connection conn = null;
try
{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "userinfo", "admin");
    out.println("connected....!!");

}

catch(Exception e)
{
    out.println("Exception : " + e.getMessage() + "");
}


%>
</BODY>
</HTML>

In the web page it is showing

HTTP Status 404 - Not Found
type Status report
messageNot Found
descriptionThe requested resource is not available.
Pshemo
  • 122,468
  • 25
  • 185
  • 269
mayukhsroy
  • 141
  • 1
  • 1
  • 9
  • 1
    What was the url seen in the browser and name of the file? –  Jun 22 '18 at 10:15
  • This does not seem like an issue with jdbc connectivity, it looks like you cannot access the resource. If there was an issue it would have been printed as a message. – Kaushik Chakraborty Jun 22 '18 at 10:19
  • http://localhost:8080/Test/ file name Test – mayukhsroy Jun 22 '18 at 10:20
  • @KaushikChakraborty Then what do you think is the problem. username and password are absolutely fine – mayukhsroy Jun 22 '18 at 10:23
  • In the debugger console it is showing.... Attaching to localhost:9009 User program running – mayukhsroy Jun 22 '18 at 10:24
  • 1
    `404` suggests that server can't find resource asked via URL. If your URL looks like `www.server.com/path/to/resource` then browser tries to connect to `www.server.com` and ask for resource placed at (or mapped as) `/path/to/resource`. In your case `/Test` is only thing you used to access your JSP file, but something tells me that `Test` is name of your WebApplication, so your URL lacks path to that JSP within your application. – Pshemo Jun 22 '18 at 10:26
  • 1
    Start with simpler things. Create simple JSP page with "hello world" and try to access it. When you succeed then you can try to modify it. BTW (this may be too advanced if you are just starting learning but it is worth to know good practices so here it goes) JSP is meant to be View (in MVC design pattern), Java logic is supposed to be in different places. Take a look at [How to avoid Java code in JSP files?](https://stackoverflow.com/q/3177733) – Pshemo Jun 22 '18 at 10:29
  • Yes i just noticed none of my jsp files are running... What shud i do? Same error each time – mayukhsroy Jun 22 '18 at 10:36
  • Have i messed up with the port numbers? – mayukhsroy Jun 22 '18 at 10:37
  • 1
    If your jsp page is not mentioned inside web.xml as a "welcome-file-list" you'll have to write it in the URL, like "localhost:8080/MyApplication/page1.jsp" or if your file is inside a folder (WebApp/pages/hello.jsp) you will have to access it with "localhost:8080/MyApplication/pages/hello.jsp", that is, if you aren't using any framework, and by what you said I believe you aren't. And yes, make sure to call the port your server is running with. – res Jun 22 '18 at 11:02
  • localhost:8080/MyApplication/pages/hello.jsp~~~~~ this is working... But this is not a permanent solution. I wasnt facing this problem earlier .. – mayukhsroy Jun 22 '18 at 11:17

0 Answers0