Solved

JSP Error

Posted on 2004-08-05
14
512 Views
Last Modified: 2010-04-01
Hi All,
I am running Tomcat 4.1.27 on Linux. Java is   Version 1.4.1-01
I have a class file DBUsernamePassword in WEB-INF/classes/<packagename>/DBUsernamePassword.class

When I try running the JSP... I get error in JSP's which use the class file....
The is what i get in log file
-------------------------------------------------------------------------------------------------------------------------------
2004-08-05 12:49:59 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: DBUsernamePassword
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)
----- Root Cause -----
javax.servlet.ServletException: DBUsernamePassword
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
at org.apache.jsp.process_login_jsp._jspService(process_login_jsp.java:261)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)
-------------------------------------------------------------------------------------------------------------------------------

Any idea what the error is?
0
Comment
Question by:chitman
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 11724841
can you post the jsp?
0
 
LVL 4

Expert Comment

by:indigostark
ID: 11724888
Yes,
Could you please post your code.
I suggest that you may have not properly imported the class
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11724956
or DBUsernamePassword is throwing an exception you do not catch in the jsp...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:chitman
ID: 11732872
I am copying part of my jsp file here
---------------------------------------------------------------
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="javax.servlet.*" %>
<jsp:useBean id="uid" class="DBUsernamePassword" scope="application" />
<%@ page import="p1.*"%>

<%
try
{
String u=uid.getUsername();
String p=uid.getPassword();

Connection conn =null;
      Class.forName("oracle.jdbc.driver.OracleDriver");

      conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@x.x.x.x:1521:db",
                u,
                p);

      stmt1 = conn.createStatement();

....
---------------------------------------------------------------
Here is my DBUsernmaePassword file
---------------------------------------------------------------
package p1;

public class DBUsernamePassword {
  public static String getUsername() {
    return "user1";
  }

  public static String getPassword() {
    return "password1";
  }
}
---------------------------------------------------------------
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 50 total points
ID: 11733461
DBUserNamePassword contains the methods getUsername () and getPassword () as static, so why do you need a bean to access them? You can directly use this:

String u = DBUserNamePassword.getUsername () ;
String p = DBUserNamePassword.getPassword () ;
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11733462
>> DBUserNamePassword

DBUsernamePassword, with a small 'n' ;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11733774
Swap these two lines over in the jsp:

<jsp:useBean id="uid" class="DBUsernamePassword" scope="application" />
<%@ page import="p1.*"%>

so that you have:

<%@ page import="p1.*"%>
<jsp:useBean id="uid" class="DBUsernamePassword" scope="application" />

You need to import the package BEFORE you call classes inside it ;-)

Tim
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11733820
>> Swap these two lines over in the jsp:

You might as well just remove <jsp:useBean....>

You can access the methods using the class-name since they are static.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11733829
True ;-)
0
 

Author Comment

by:chitman
ID: 11733840
Hi...
It did work... but I want to know the differnce between the following code

<%@ page import="p1.*"%>
<%
String u = DBUsernamePassword.getUsername() ;
String p = DBUsernamePassword.getPassword() ;
%>


 and


<jsp:useBean id="uid" class="DBUsernamePassword" scope="application" />

<%
String u=uid.getUsername();
String p=uid.getPassword();
%>
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11733858
The second would've been fine if you had the methods defined as:

public String getUsername() {

instead of: >> public static String getUsername() {

(note the difference is the 'static' keyword'). When you define a bean "uid", it is like an object of the class "DBUsernamePassword", and so, you can access the getUsernamePassword () method with it. But if the method is static, you don't need the object and you can access it directly by using the class-name like ClassName.method () ;

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11733864
0
 

Author Comment

by:chitman
ID: 11733893
THANKS A LOT...
:)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11733925
:-)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Stuck in Bootstrap WysiHtml Editor 3 42
spring dependency injection using java config 2 89
gZip compression filter 2 174
parse example 13 95
Read about why it is more lucrative for an IT company to participate in government projects.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question