Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP error with tomcat: can't find write method  RSS feed

 
Eckhard Beisswenger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I receive an error in a jsp application when it's running with tomcat, though the error doesn't occur with WebLogic.
The JSP uses a bean called "porto.tachart.DBConnect" which contains a property called "authentication" and the corresponding set method:
public void setAuthentication(HttpServletRequest request) {
authentication = checkAuth(request);
// the checkAuth method works fine
}
However, tomcat won't find the set method for "authentication" (though other set methods which are called earlier are found). tomcat throws this error message:
org.apache.jasper.JasperException: Can't find a method to write property 'authentication' in a bean of type 'porto.tachart.DBConnect'
at org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(Unknown Source)
at index_4._jspService(index_4.java, Compiled Code)
at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code)
at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source)
at org.apache.tomcat.core.Handler.invoke(Unknown Source)
at org.apache.tomcat.core.Handler.service(Unknown Source)
at org.apache.tomcat.facade.ServletHandler.service(Unknown Source)
at org.apache.tomcat.core.ContextManager.internalService(Unknown Source)
at org.apache.tomcat.core.ContextManager.service(Unknown Source)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Unknown Source)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(Unknown Source)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java, Compiled Code)
I'll be glad for any help. Many thanks in advance,
Eckhard Beisswenger
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please show the snipit of jsp code that creates and uses the bean?
 
Eckhard Beisswenger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thanks for your prompt response.
Here's the beginning of my JSP file:
<%@ page contentType="text/html;charset=ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.net.URLEncoder" %>
<%! int auth; %>
<jsp:useBean class="porto.tachart.DBConnect" id="dbBean" scope="page"/>
<jsp:setProperty name="dbBean" property="servletContext" value="<%= getServletConfig().getServletContext() %>"/>
<jsp:setProperty name="dbBean" property="authentication" value="<%= request %>"/>
I wonder why the calling of "setServletContext" works without errors while the calling of "srtAuthentication" doesn't.
Any ideas?
Eckhard Beisswenger
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi - In the bean, what kind of object is 'authentication'?
Regards, Guy
 
Eckhard Beisswenger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'authentication' is an int. It is declared at the beginning of the bean's code as a class variable. It's value will then be set by the 'checkAuth()' method: this method uses a HttpServletRequest object to check authorization of the user request and then sets the value of 'authentication' to the resulting HTTP status code (eg. 202, if the authentication was successful).
After the setting of this value, 'authentication' is returned by a 'getAuthentication()' method.
Here's the code of 'checkAuth(HttpServletRequest request)' and 'getAuthentication()':
private int checkAuth (HttpServletRequest request) {
System.out.println("NOVA Porto - checkAuth()");
// Only allow user guest with password welcome to log on
String authHeader = request.getHeader ("authorization");
if (authHeader != null) {
if (authHeader.substring(0, 6).equals("Basic ")) {
String authstring;
try {
authstring = new String(new BASE64Decoder().decodeBuffer (authHeader.substring (6)));
System.out.println("NOVA Porto - checkAuth(): authentication header is valid");
}
catch (java.io.IOException e) {
// could not make input for decodeBuffer
return AUTH_ERROR;
}
int colonpos = authstring.indexOf (":");
if (colonpos != authstring.lastIndexOf (":"))
return AUTH_WRONG; // Don't accept authstring with more than one colon
user = authstring.substring (0, colonpos);
passwd = authstring.substring (colonpos+1);
if (user != null && passwd != null) {
System.out.println("NOVA Porto - checkAuth(): connecting to database");
// creating db-connection and storing it in a Connection-Object
try {
String driver = servletContext.getInitParameter("driver");
String driver_url = servletContext.getInitParameter("driver_url");
String sid = servletContext.getInitParameter("sid");

Properties props = new Properties();
props.put("user",user);
props.put("password",passwd);
props.put("server",sid);
Driver myDriver = (Driver)Class.forName(driver).newInstance();
connection = myDriver.connect(driver_url, props);
statement = connection.createStatement();
System.out.println("NOVA Porto - checkAuth(): connection and statement created");
return AUTH_OK;
} catch(SQLException msg){
if ( msg.toString().indexOf("ORA-01017") != 0 ) {
// Invalid Username/Password; logon denied
System.err.println("NOVA Porto - checkAuth(): ORA-01017-case " + msg.getMessage());
return AUTH_WRONG;
}
else {
// Other SQL Exception
System.err.println("NOVA Porto - checkAuth(): Other SQL Exception " + msg.getMessage());
return AUTH_ERROR;
}
} catch(Exception e) {
// Other Exception
System.err.println("NOVA Porto - checkAuth(): Other Exception " + e.getMessage());
return AUTH_ERROR;
}
}
else {
// username or password is null
System.err.println("NOVA Porto - checkAuth(): username or password is null");
return AUTH_WRONG;
}
}
else // no Basic authentication
return AUTH_WRONG;
}
else // no authentication header at all
return AUTH_WRONG;
}

public int getAuthentication() {
System.out.println("NOVA Porto - getAuthentication(): "+authentication);
return authentication;
}

Many thanks for your help,
Eckhard
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!