Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

write userdefined method into HttpServlet.

 
mohamed mustaq
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have a doubt that how to write a user defined method inside the doPost method in HttpServlet.\
i hereby enclosed my code for easy understanding.
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your doubt ?
You did not pass "out" to your method.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohamed,

Javaranch tip:
If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic