On 3/22/07, yoursoft <[EMAIL PROTECTED]> wrote:
Dear List,

I found that in new Velocity the VelocityServelt depricated, and will be
removed.

I would like to migrate my existing sources to new structure (assign all
*.vm to VelocityViewServelt (VVS) (or extend VVS as VelocityServelt?) ),
but I have some mistakes.

you'll want to extend the VVS.   it should only require three changes:

import org.apache.velocity.tools.view.servlet.VelocityViewServlet;

extends VelocityViewServlet //(instead of VelocityServlet)

getVelocityEngine().getTemplate(...); //instead of Velocity.getTemplate(...)

My current servlets code structure are like followings:

package wf.fizel;

import java.sql.Connection;
import java.sql.ResultSet;
import javax.naming.InitialContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.view.servlet.VelocityViewServlet;
import my.system.SessionParser;
import my.system.Tools;
import my.system.exceptionhandling.MyException;
import my.system.utils.*;


public class Igeny extends VelocityViewServlet {

    private DataSource poolWorkFlow = null; // DB connection pool

    public void init(ServletConfig config) throws ServletException {
        super.init(config);

        InitialContext initCtx = null;
        try {
            initCtx = new InitialContext();
            pri_poolWorkFlow = (DataSource)
initCtx.lookup("java:comp/env/jdbc/workflow");
        } catch (Exception e) {
            throw new ServletException("no datasource found " +e);
        }
    }

    public Template handleRequest( HttpServletRequest req,
HttpServletResponse resp,  Context context){

        Template template = null;
        StringBuffer sb = new StringBuffer();
        final String lang = req.getParameter("lang");
        final String companyId = req.getParameter("companyId");
        String id2 = "";
        SessionParser sessionp = null;
        Connection db = null;
        ResultSet rs = null;
        int max=0;

        try {
            sessionp = new SessionParser( req.getSession(false) );
            db = poolWorkFlow.getConnection();

            rs = Utils.getMan( sessionp.getStringParameter("userid"), db);
           String options = Options.setOptionValue(rs, "", false);

            try {
                rs.first();
                context.put("ORIGMAN", rs.getString(1));
                rs.close();
            } catch (Exception e) {}

            sb.append("select * from table where userid::text) ='");
            sb.append(sessionp.getStringParameter("userid"));
            sb.append("'");
            rs = Db.getSql(sb.toString(), db);
            if (rs.first()) {
                id2 = rs.getString("id");
                max = rs.getInt("min_paid")*3;
            } else {
                throw new Exception("wrong parameter!");
            }
.....

            context.put("MAX", Szoveg.getIntStr(max,"###,###,###", '.'));
            context.put("MAX_NUM", String.valueOf(max));
            context.put("ID", id2);

            context.put("LANG", lang );
            context.put("COMPANY",  companyId);
            context.put("SESSION", (req.getSession(false)).getId());

            template = getVelocityEngine().getTemplate(
                    MyStrings.getTemplateName(sb.toString(), lang,
companyId));
        } catch( Exception e ) {
            MyException.forward(e, 1, req, resp);
        } finally {
            try {db.close(); } catch (Exception e2) {}
        }

        return template;
    }
}

How you can rewrite this code structure into VVS? Can you help to me
with an example? :-)
I don't would like to decrease server performance.

Regards,
    Ferenc

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to