Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to write user defined method into doPost method in httpservlet

 
mohamed mustaq
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to write my own method into doPost method in HttpServlet.
i hereby enclosed my code here for clear view.
thanks.


/*
* Created on Feb 8, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package analyserQuery;

import javax.servlet.http.HttpServlet;

import java.io.IOException;
import java.io.PrintWriter;
import oracle.jdbc.OracleResultSetMetaData;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;





/**
* Servlet Class
*
* @web.servlet name="QueryAnalyser"
* display-name="Name for QueryAnalyser"
* description="Description for QueryAnalyser"
* @web.servlet-mapping url-pattern="/QueryAnalyser"
* @web.servlet-init-param name="A parameter"
* value="A value"
*/
public class QueryAnalyser extends HttpServlet
{
public void rdesc(HttpServletRequest req,HttpServletResponse res)
{
/*java.sql.ResultSet res=null;




java.sql.ResultSetMetaData res1=null;

OracleResultSetMetaData rmd=(OracleResultSetMetaData)res.getMetaData();
int columnCount=rmd.getColumnCount();

out.println("Total Number of Columns:"+columnCount+"<br>");
out.println("<html><body><table><tr><td>Coulmn Name:</td>");
out.println("<td>Coulmn Type:</td>");
out.println("<td>Coulmn Size:</td></tr>");
for(int i=1;i<=columnCount;i++)
{
String colname=rmd.getColumnName(i);
String coltype=rmd.getColumnTypeName(i);
if(coltype=="DATE")
{
colsize=rmd.getColumnDisplaySize(i);
}
else
colsize=rmd.getPrecision(i);
//int noofrows=rmd.getPrecision(i);
//int dates=rmd.getColumnDisplaySize(i);
out.println("<tr><td>"+colname+"</td>");
out.println("<td>"+coltype+"</td>");
out.println("<td>"+colsize+"</td>");

}
out.println("</table></body></html>");*/

}

public void doPost(
HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{


String Employeenumber=null;
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String uname=request.getParameter("username");

validatorBean bean=new validatorBean();
bean.setUsername(request.getParameter("username"));
bean.setPassword(request.getParameter("password"));
bean.setHost(request.getParameter("host"));
String query=request.getParameter("query");
int colsize;
try
{
bean.dbConnect();
public void rdesc(request,response);
java.sql.ResultSet res=null;

java.sql.Statement st=bean.con.createStatement();
res=st.executeQuery(query);


java.sql.ResultSetMetaData res1=null;

OracleResultSetMetaData rmd=(OracleResultSetMetaData)res.getMetaData();
int columnCount=rmd.getColumnCount();

out.println("Total Number of Columns:"+columnCount+"<br>");
out.println("<html><body><table><tr><td>Coulmn Name:</td>");
out.println("<td>Coulmn Type:</td>");
out.println("<td>Coulmn Size:</td></tr>");
for(int i=1;i<=columnCount;i++)
{
String colname=rmd.getColumnName(i);
String coltype=rmd.getColumnTypeName(i);
if(coltype=="DATE")
{
colsize=rmd.getColumnDisplaySize(i);
}
else
colsize=rmd.getPrecision(i);
//int noofrows=rmd.getPrecision(i);
//int dates=rmd.getColumnDisplaySize(i);
out.println("<tr><td>"+colname+"</td>");
out.println("<td>"+coltype+"</td>");
out.println("<td>"+colsize+"</td>");

}
out.println("</table></body></html>");

}catch(Exception e)
{
out.println(e.getMessage());
}
}//end dopost method
/*public void rdesc()
{
java.sql.ResultSet res=null;




java.sql.ResultSetMetaData res1=null;

OracleResultSetMetaData rmd=(OracleResultSetMetaData)res.getMetaData();
int columnCount=rmd.getColumnCount();

out.println("Total Number of Columns:"+columnCount+"<br>");
out.println("<html><body><table><tr><td>Coulmn Name:</td>");
out.println("<td>Coulmn Type:</td>");
out.println("<td>Coulmn Size:</td></tr>");
for(int i=1;i<=columnCount;i++)
{
String colname=rmd.getColumnName(i);
String coltype=rmd.getColumnTypeName(i);
if(coltype=="DATE")
{
colsize=rmd.getColumnDisplaySize(i);
}
else
colsize=rmd.getPrecision(i);
//int noofrows=rmd.getPrecision(i);
//int dates=rmd.getColumnDisplaySize(i);
out.println("<tr><td>"+colname+"</td>");
out.println("<td>"+coltype+"</td>");
out.println("<td>"+colsize+"</td>");

}
out.println("</table></body></html>");


}*/ //methiod redesc ends




}//servlest ends here
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Do you have a question about this?
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic