File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes write userdefined method into HttpServlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "write userdefined method into HttpServlet." Watch "write userdefined method into HttpServlet." New topic
Author

write userdefined method into HttpServlet.

mohamed mustaq
Greenhorn

Joined: Dec 19, 2005
Posts: 21
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

What is your doubt ?
You did not pass "out" to your method.


[My Blog]
All roads lead to JavaRanch
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: write userdefined method into HttpServlet.