cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beyaNet Consultancy <>
Subject Action problem
Date Sat, 17 Jan 2004 21:34:03 GMT
I have written an action which is meant to, for the meantime, return a 
single column value. The problem is that you continually keep getting 
redirected to the login page, which is meant to happen if a map is not 
returned successfully. What am I missing?

This action is called from a login page as so:


<form action="testpage" method="post"?

2. sitemap

			<map:match pattern="testpage">
				<map:act type="get-detail2">
					<map:generate type="file" src="content/main.xml" />
					<map:transform scr="style/main.xsl">
						<map:parameter name="first_name" value="{first_name}" />
			<map:redirect-to uri="login.html" />

3. Action

package test;

import org.apache.avalon.excalibur.datasource.DataSourceComponent;

import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentSelector;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.cocoon.Constants;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.acting.AbstractAction;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

public class GetUserDetail2 extends AbstractAction implements 
ThreadSafe, Composable, Disposable
	protected ComponentSelector dbselector;
	protected ComponentManager manager;
	public void compose(ComponentManager manager) throws ComponentException
		this.dbselector = (ComponentSelector)
			manager.lookup(DataSourceComponent.ROLE + "Selector");
	protected final DataSourceComponent getDataSource(String pool) throws 
		return (DataSourceComponent);
	public Map act ( Redirector redirector, SourceResolver resolver,
					 Map objectModel, String source, Parameters param) throws Exception
		Request request = ObjectModelHelper.getRequest(objectModel);
		Map map = new HashMap();
		DataSourceComponent dataSource = getDataSource("postgresql");
		Connection conn = null;
			conn = dataSource.getConnection();
			Statement stmt = conn.createStatement();
			String cmd = "Select user_id, first_name, last_name, address1, 
address2, address3, postcode, country, email, home_telephone, 
mobile_telephone, date_joined from usertbl where username = 'x' and 
userpassword = 'y'";
			ResultSet rs = stmt.executeQuery(cmd);
			if (
				map.put("first_name", rs.getString(1));
		}catch (Exception e){
			getLogger().error("Query failed: ", e);
				if (conn != null) conn.close();
			}catch (SQLException sqe)
				getLogger().warn("Error closing the datasource", sqe);
		return (map);
	public void dispose()
View raw message