Solved

JSP Error

Posted on 2004-08-05
14
510 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
communication with a non technical owner 16 100
hashcode is calculated on the basis of value object 2 103
bean mapper frameworks 5 59
mask rule in struts validation.xml 5 85
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

930 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now