aspose file tools*
The moose likes Servlets and the fly likes i have edited now tell me where i am wrong Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "i have edited now tell me where i am wrong" Watch "i have edited now tell me where i am wrong" New topic
Author

i have edited now tell me where i am wrong

syed mahboob
Greenhorn

Joined: Dec 06, 2012
Posts: 15




package com.lara.servlets.controller;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Connection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lara.db.pool.ConnectionPool;
import com.lara.model.Action;
import com.lara.model.Bean;
import com.lara.model.RequestInfo;
import com.lara.xml.ModuleConfig;

/**
* Servlet implementation class ControllerServlet
*/
public class ControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ConnectionPool cp=null;
private ModuleConfig moduleConfig=null;


public ControllerServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see Servlet#init(ServletConfig)
*/
public void init() throws ServletException {

String driverClass=getInitParameter("driverClass");
String url=getInitParameter("url");
String username=getInitParameter("username");
String password=getInitParameter("password");
String poolSize=getInitParameter("poolSize");
int intPoolSize=Integer.parseInt(poolSize);
cp=new ConnectionPool(driverClass,url,username,
password,intPoolSize);
cp.init();
// TODO Auto-generated method stub

String fileName=getInitParameter("config-file");
InputStream is = getClass().getResourceAsStream((new StringBuilder("/../")).append(fileName).toString());

try{
moduleConfig=new ModuleConfig(is);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
// TODO Auto-generated method stub


/**
* @see Servlet#destroy()
*/
public void destroy() {
cp.release();
// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPerform(request,response);

// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPerform(request,response);
// TODO Auto-generated method stub
}
private void doPerform(HttpServletRequest request,
HttpServletResponse response) throws ServletException,IOException

{
String path=request.getServletPath();
path=path.substring(1,path.length()-3);
Connection con=cp.checkOut();
request.setAttribute("con",con);
RequestInfo reqInfo=moduleConfig.getRequestInfo(path);
String beanClass=reqInfo.getBeanClass();
Bean beanObj=getBeanObject(beanClass,request);
String actionClass=reqInfo.getActionClass();
Action actionObj=getActionObject(actionClass);
String result=actionObj.process(request, beanObj);
String resultPath=reqInfo.getForward(result);
RequestDispatcher rd=request.getRequestDispatcher(resultPath);
rd.forward(request, response);
request.removeAttribute("con");
cp.checkIn(con);

}
private Bean getBeanObject(String beanClass,HttpServletRequest request)
{
Object obj=null;
Class cls=null;
try
{
cls=Class.forName(beanClass);
obj=cls.newInstance();
}
catch(Exception ex)
{
ex.printStackTrace();
}
Field all[]=cls.getDeclaredFields();
String methodName=null;
Method methodObj=null;
String fieldName;
String fieldValue;
for(Field f1:all)
{
fieldName=f1.getName();
fieldValue=request.getParameter(fieldName);
if(fieldValue!=null)
{
methodName="set"+fieldName.substring(0,1).toUpperCase()+fieldName.substring(1);
try
{
methodObj=cls.getDeclaredMethod(methodName,f1.getType());
if(f1.getType().equals(String.class))
{
methodObj.invoke(obj,fieldValue);
}
if(f1.getType().equals(Byte.class))
{
methodObj.invoke(obj,new Byte(fieldValue));
}
if(f1.getType().equals(Short.class))
{
methodObj.invoke(obj,new Short(fieldValue));
}
if(f1.getType().equals(Integer.class))
{
methodObj.invoke(obj,new Integer(fieldValue));
}
if(f1.getType().equals(Float.class))
{
methodObj.invoke(obj,new Float(fieldValue));
}
if(f1.getType().equals(Long.class))
{
methodObj.invoke(obj,new Long(fieldValue));
}
if(f1.getType().equals(Double.class))
{
methodObj.invoke(obj,new Double(fieldValue));
}
if(f1.getType().equals(byte.class))
{
methodObj.invoke(obj,Byte.parseByte(fieldValue));
}
if(f1.getType().equals(short.class))
{
methodObj.invoke(obj,Short.parseShort(fieldValue));
}
if(f1.getType().equals(int.class))
{
methodObj.invoke(obj,Integer.parseInt(fieldValue));
}
if(f1.getType().equals(long.class))
{
methodObj.invoke(obj,Long.parseLong(fieldValue));
}
if(f1.getType().equals(float.class))
{
methodObj.invoke(obj,Float.parseFloat(fieldValue));
}
if(f1.getType().equals(double.class))
{
methodObj.invoke(obj,Double.parseDouble(fieldValue));
}
if(f1.getType().equals(String[].class))
{
String x[]=request.getParameterValues(fieldName);
methodObj.invoke(obj,new Object[]{x});
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
fieldValue=null;
}
return (Bean)obj;

}

private Action getActionObject(String actionClass)
{
Object obj=null;
try
{
obj=Class.forName(actionClass).newInstance();
}
catch(Exception ex)
{
ex.printStackTrace();
}
return (Action)obj;
}

}







[Post New]posted Today 12:07:26 PM
Quote Edit
view plaincopy to clipboardprint?

package com.lara.servlets.controller;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Connection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lara.db.pool.ConnectionPool;
import com.lara.model.Action;
import com.lara.model.Bean;
import com.lara.model.RequestInfo;
import com.lara.xml.ModuleConfig;

/**
* Servlet implementation class ControllerServlet
*/
public class ControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ConnectionPool cp=null;
private ModuleConfig moduleConfig=null;


public ControllerServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see Servlet#init(ServletConfig)
*/
public void init() throws ServletException {

String driverClass=getInitParameter("driverClass");
String url=getInitParameter("url");
String username=getInitParameter("username");
String password=getInitParameter("password");
String poolSize=getInitParameter("poolSize");
int intPoolSize=Integer.parseInt(poolSize);
cp=new ConnectionPool(driverClass,url,username,
password,intPoolSize);
cp.init();
// TODO Auto-generated method stub

String fileName=getInitParameter("config-file");
InputStream is = getClass().getResourceAsStream((new StringBuilder("/../")).append(fileName).toString());

try{
moduleConfig=new ModuleConfig(is);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
// TODO Auto-generated method stub


/**
* @see Servlet#destroy()
*/
public void destroy() {
cp.release();
// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPerform(request,response);

// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPerform(request,response);
// TODO Auto-generated method stub
}
private void doPerform(HttpServletRequest request,
HttpServletResponse response) throws ServletException,IOException

{
String path=request.getServletPath();
path=path.substring(1,path.length()-3);
Connection con=cp.checkOut();
request.setAttribute("con",con);
RequestInfo reqInfo=moduleConfig.getRequestInfo(path);
String beanClass=reqInfo.getBeanClass();
Bean beanObj=getBeanObject(beanClass,request);
String actionClass=reqInfo.getActionClass();
Action actionObj=getActionObject(actionClass);
String result=actionObj.process(request, beanObj);
String resultPath=reqInfo.getForward(result);
RequestDispatcher rd=request.getRequestDispatcher(resultPath);
rd.forward(request, response);
request.removeAttribute("con");
cp.checkIn(con);

}
private Bean getBeanObject(String beanClass,HttpServletRequest request)
{
Object obj=null;
Class cls=null;
try
{
cls=Class.forName(beanClass);
obj=cls.newInstance();
}
catch(Exception ex)
{
ex.printStackTrace();
}
Field all[]=cls.getDeclaredFields();
String methodName=null;
Method methodObj=null;
String fieldName;
String fieldValue;
for(Field f1:all)
{
fieldName=f1.getName();
fieldValue=request.getParameter(fieldName);
if(fieldValue!=null)
{
methodName="set"+fieldName.substring(0,1).toUpperCase()+fieldName.substring(1);
try
{
methodObj=cls.getDeclaredMethod(methodName,f1.getType());
if(f1.getType().equals(String.class))
{
methodObj.invoke(obj,fieldValue);
}
if(f1.getType().equals(Byte.class))
{
methodObj.invoke(obj,new Byte(fieldValue));
}
if(f1.getType().equals(Short.class))
{
methodObj.invoke(obj,new Short(fieldValue));
}
if(f1.getType().equals(Integer.class))
{
methodObj.invoke(obj,new Integer(fieldValue));
}
if(f1.getType().equals(Float.class))
{
methodObj.invoke(obj,new Float(fieldValue));
}
if(f1.getType().equals(Long.class))
{
methodObj.invoke(obj,new Long(fieldValue));
}
if(f1.getType().equals(Double.class))
{
methodObj.invoke(obj,new Double(fieldValue));
}
if(f1.getType().equals(byte.class))
{
methodObj.invoke(obj,Byte.parseByte(fieldValue));
}
if(f1.getType().equals(short.class))
{
methodObj.invoke(obj,Short.parseShort(fieldValue));
}
if(f1.getType().equals(int.class))
{
methodObj.invoke(obj,Integer.parseInt(fieldValue));
}
if(f1.getType().equals(long.class))
{
methodObj.invoke(obj,Long.parseLong(fieldValue));
}
if(f1.getType().equals(float.class))
{
methodObj.invoke(obj,Float.parseFloat(fieldValue));
}
if(f1.getType().equals(double.class))
{
methodObj.invoke(obj,Double.parseDouble(fieldValue));
}
if(f1.getType().equals(String[].class))
{
String x[]=request.getParameterValues(fieldName);
methodObj.invoke(obj,new Object[]{x});
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
fieldValue=null;
}
return (Bean)obj;

}

private Action getActionObject(String actionClass)
{
Object obj=null;
try
{
obj=Class.forName(actionClass).newInstance();
}
catch(Exception ex)
{
ex.printStackTrace();
}
return (Action)obj;
}

}







HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet ControllerServlet threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
com.lara.servlets.controller.ControllerServlet.init(ControllerServlet.java:46)
javax.servlet.GenericServlet.init(GenericServlet.java:212)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Unknown Source)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.28 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.28
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
1. Since the error was in the init method you did not need to burden us with that huge code listing.
2. Read this carefully - it guides you directly to the problem:



Obviously the parseInt method was called with a null reference - due to the failure of the previous code to find an init parameter with the name used.

3. You are still not using code tags properly.

Bill
syed mahboob
Greenhorn

Joined: Dec 06, 2012
Posts: 15


package com.lara.servlets.controller;

import java.io.IOException;

import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Connection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lara.db.pool.ConnectionPool;
import com.lara.model.Action;
import com.lara.model.Bean;
import com.lara.model.RequestInfo;
import com.lara.xml.ModuleConfig;

/**
* Servlet implementation class ControllerServlet
*/
public class ControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ConnectionPool cp=null;
private ModuleConfig moduleConfig=null;

public ControllerServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see Servlet#init(ServletConfig)
*/
public void init() throws ServletException {

String driverClass=getInitParameter("driverClass");
String url=getInitParameter("url");
String username=getInitParameter("username");
String password=getInitParameter("password");
String poolSize=getInitParameter("poolSize");
int intPoolSize=Integer.parseInt(poolSize);
cp=new ConnectionPool(driverClass,url,username,
password,intPoolSize);
cp.init();
// TODO Auto-generated method stub

String fileName=getInitParameter("config-file");
InputStream is = getClass().getResourceAsStream((new StringBuilder("/../")).append(fileName).toString());

try{
moduleConfig=new ModuleConfig(is);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
// TODO Auto-generated method stub


/**
* @see Servlet#destroy()
*/
public void destroy() {
cp.release();
// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPerform(request,response);

// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPerform(request,response);
// TODO Auto-generated method stub
}
private void doPerform(HttpServletRequest request,
HttpServletResponse response) throws ServletException,IOException

{
String path=request.getServletPath();
path=path.substring(1,path.length()-3);
Connection con=cp.checkOut();
request.setAttribute("con",con);
RequestInfo reqInfo=moduleConfig.getRequestInfo(path);
String beanClass=reqInfo.getBeanClass();
Bean beanObj=getBeanObject(beanClass,request);
String actionClass=reqInfo.getActionClass();
Action actionObj=getActionObject(actionClass);
String result=actionObj.process(request, beanObj);
String resultPath=reqInfo.getForward(result);
RequestDispatcher rd=request.getRequestDispatcher(resultPath);
rd.forward(request, response);
request.removeAttribute("con");
cp.checkIn(con);

}
private Bean getBeanObject(String beanClass,HttpServletRequest request)
{
Object obj=null;
Class cls=null;
try
{
cls=Class.forName(beanClass);
obj=cls.newInstance();
}
catch(Exception ex)
{
ex.printStackTrace();
}
Field all[]=cls.getDeclaredFields();
String methodName=null;
Method methodObj=null;
String fieldName;
String fieldValue;
for(Field f1:all)
{
fieldName=f1.getName();
fieldValue=request.getParameter(fieldName);
if(fieldValue!=null)
{
methodName="set"+fieldName.substring(0,1).toUpperCase()+fieldName.substring(1);
try
{
methodObj=cls.getDeclaredMethod(methodName,f1.getType());
if(f1.getType().equals(String.class))
{
methodObj.invoke(obj,fieldValue);
}
if(f1.getType().equals(Byte.class))
{
methodObj.invoke(obj,new Byte(fieldValue));
}
if(f1.getType().equals(Short.class))
{
methodObj.invoke(obj,new Short(fieldValue));
}
if(f1.getType().equals(Integer.class))
{
methodObj.invoke(obj,new Integer(fieldValue));
}
if(f1.getType().equals(Float.class))
{
methodObj.invoke(obj,new Float(fieldValue));
}
if(f1.getType().equals(Long.class))
{
methodObj.invoke(obj,new Long(fieldValue));
}
if(f1.getType().equals(Double.class))
{
methodObj.invoke(obj,new Double(fieldValue));
}
if(f1.getType().equals(byte.class))
{
methodObj.invoke(obj,Byte.parseByte(fieldValue));
}
if(f1.getType().equals(short.class))
{
methodObj.invoke(obj,Short.parseShort(fieldValue));
}
if(f1.getType().equals(int.class))
{
methodObj.invoke(obj,Integer.parseInt(fieldValue));
}
if(f1.getType().equals(long.class))
{
methodObj.invoke(obj,Long.parseLong(fieldValue));
}
if(f1.getType().equals(float.class))
{
methodObj.invoke(obj,Float.parseFloat(fieldValue));
}
if(f1.getType().equals(double.class))
{
methodObj.invoke(obj,Double.parseDouble(fieldValue));
}
if(f1.getType().equals(String[].class))
{
String x[]=request.getParameterValues(fieldName);
methodObj.invoke(obj,new Object[]{x});
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
fieldValue=null;
}
return (Bean)obj;

}



private Action getActionObject(String actionClass)
{
Object obj=null;
try
{
obj=Class.forName(actionClass).newInstance();
}
catch(Exception ex)
{
ex.printStackTrace();
}
return (Action)obj;
}

}




HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
com.lara.servlets.controller.ControllerServlet.getBeanObject(ControllerServlet.java:124)
com.lara.servlets.controller.ControllerServlet.doPerform(ControllerServlet.java:100)
com.lara.servlets.controller.ControllerServlet.doPost(ControllerServlet.java:87)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.28 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.28


package com.lara.client;

import java.sql.Connection;

import javax.servlet.http.HttpServletRequest;

import com.lara.model.Action;
import com.lara.model.Bean;

public class LoginAction extends Action {

public String process(HttpServletRequest request,Bean bean)
{
Connection con=(Connection)request.getAttribute("con");
LoginBean loginBean=(LoginBean) bean;
boolean status=LoginDAO.authenticate(con,loginBean);
if(status)
return "success";
request.setAttribute("param.username","Wrong username or password");
return "failure";
}
}




package com.lara.client;

import com.lara.model.Bean;

public class LoginBean extends Bean {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}


}




package com.lara.client;

import java.sql.Connection;

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

import com.lara.db.util.DBUtil;



public class LoginDAO {
public static boolean authenticate(Connection con,LoginBean bean)
{
String username =bean.getUsername();
String password=bean.getPassword();
Statement stmt=null;
ResultSet rs=null;
String sqlQry="";

try{
stmt=con.createStatement();
sqlQry="select * from users where username='"+username+"' and password='"+password+"'";

rs=stmt.executeQuery(sqlQry);
return rs.next();
}
catch(SQLException ex)
{
ex.printStackTrace();
}
finally{
DBUtil.closeResultSet(rs);
DBUtil.closeStatement(stmt);
}
return false;
}

}



package com.lara.model;

import javax.servlet.http.HttpServletRequest;

public class Action {
public String process(HttpServletRequest request,Bean bean)
{
return null;
}
}



package com.lara.model;

public class Bean {

}




package com.lara.model;

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

public class RequestInfo {
private String path;
private String beanClass;
private String actionClass;
private Map<String,String> paths=new HashMap<String,String>();
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getBeanClass() {
return beanClass;
}
public void setBeanClass(String beanClass) {
this.beanClass = beanClass;
}
public String getActionClass() {
return actionClass;
}
public void setActionClass(String actionClass) {
this.actionClass = actionClass;
}
public void putForward(String key,String value)
{
paths.put(key,value);
}
public String getForward(String name)
{
return paths.get(name);
}


}




package com.lara.xml;

import java.io.InputStream;

import java.util.HashMap;


import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.lara.model.RequestInfo;

public class ModuleConfig extends DefaultHandler
{
private HashMap<String,RequestInfo> reqInfos=new HashMap<String,RequestInfo>();
private String content=null;
private RequestInfo reqInfo=null;
private String reqPath=null;
private String forwardName=null;
public ModuleConfig(InputStream is) throws Exception
{
SAXParserFactory sax=SAXParserFactory.newInstance();
SAXParser sp=sax.newSAXParser();
sp.parse(is,this);
}
public void startElement(String uri,String localName,String qName,Attributes attributes) throws SAXException
{
if("request-info".equals(qName))
{
reqInfo=new RequestInfo();
}
if("forward".equals(qName))
{
forwardName=attributes.getValue("name");
}
}
public void characters(char[] ch,int start,int length) throws SAXException
{
content=new String(ch,start,length);
content=content.trim();
}
public void endElement(String uri,String localName,String qName) throws SAXException
{
if("request-info".equals(qName))
{
reqInfos.put(reqPath, reqInfo);
}
if("path".equals(qName))
{
reqInfo.setPath(content);
reqPath=content;
}
if("bean-class".equals(qName))
{
reqInfo.setBeanClass(content);

}

if("action-class".equals(qName))
{
reqInfo.setActionClass(content);

}
if("forward".equals(qName))
{
reqInfo.putForward(forwardName,content);

}
}
public RequestInfo getRequestInfo(String path)
{
return reqInfos.get(path);
}
}






<app-config>
<request-info>
<path>login</path>
<bean-class>
com.lara.client.LoginBean
</bean-class>
<action-class>
com.lara.client.LoginBean
</action-class>
<forward name="success">
success.jsp
</forward>
<forward name="failure">
login.jsp
</forward>
</request-info>
<request-info>
<path>reg</path>
<bean-class>
com.lara.client.RegistrationBean
</bean-class>
<action-class>
com.lara.client.RegistrationAction
</action-class>
<forward name="success">
regSuccess.jsp
</forward>
<forward name="failure">
reg.jsp
</forward>
</request-info>
</app-config>




<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>project</display-name>
<servlet>
<description>
</description>
<display-name>ControllerServlet</display-name>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>com.lara.servlets.controller.ControllerServlet</servlet-class>
<init-param>
<description>
</description>
<param-name>driverClass</param-name>
<param-value>oracle.jdbc.driver.OracleDriver</param-value>
</init-param>
<init-param>
<description>
</description>
<param-name>url</param-name>
<param-value>jdbcracle:thin:@localhost:1521:XE</param-value>
</init-param>
<init-param>
<description>
</description>
<param-name>username</param-name>
<param-value>test</param-value>
</init-param>
<init-param>
<description>
</description>
<param-name>password</param-name>
<param-value>syed</param-value>
</init-param>
<init-param>
<description>
</description>
<param-name>poolSize</param-name>
<param-value>10</param-value>
</init-param>

<init-param>
<param-name>config-file</param-name>
<param-value>
config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>



<servlet-mapping>
<servlet-name>ControllerServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>


${status}
<form action="login.do?" method="post">
Username: <input type="text" name="username" value="${param.username}" />
</br> Password: <input type="password" name="password" /> </br> <input
type="submit" value="submit" />

</form>










Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42918
    
  68
Have you done what I advised you to do in the other topic where you asked about this - to print out the values before using them? That should point to the problem real quick. I suspect if you had done that you'd have solved this problem quite a while ago.

Also, please read this page now: https://www.coderanch.com/how-to/java/UseCodeTags. The opening part goes before the code, and the closing part goes after it. As you have it, both parts are before the code, and thus it doesn't work. That should be obvious if you look at it, no?
syed mahboob
Greenhorn

Joined: Dec 06, 2012
Posts: 15




now i am getting this exception



HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.ClassCastException: com.lara.client.LoginBean
com.lara.servlets.controller.ControllerServlet.getActionObject(ControllerServlet.java:223)
com.lara.servlets.controller.ControllerServlet.doPerform(ControllerServlet.java:104)
com.lara.servlets.controller.ControllerServlet.doPost(ControllerServlet.java:84)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.28 logs.











Dec 9, 2012 8:56:47 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/46 config=null
Dec 9, 2012 8:56:47 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Dec 9, 2012 8:56:47 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2883 ms
/login.do
login
beanClass:com.lara.client.LoginBean,path:login,actionClass:com.lara.client.LoginBean
com.lara.client.LoginBean
com.lara.client.LoginBean@2bd3a
Dec 9, 2012 8:56:49 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet ControllerServlet threw exception
java.lang.ClassCastException: com.lara.client.LoginBean
at com.lara.servlets.controller.ControllerServlet.getActionObject(ControllerServlet.java:223)
at com.lara.servlets.controller.ControllerServlet.doPerform(ControllerServlet.java:104)
at com.lara.servlets.controller.ControllerServlet.doPost(ControllerServlet.java:84)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i have edited now tell me where i am wrong