Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

servlet question

Status
Not open for further replies.

ja0va00

Technical User
Joined
Feb 9, 2001
Messages
5
Location
US
I have a servlet that is taking parameters passed to it, I need to pass it to another java class. Can anyone help me out here..


public class CMInputServlet extends HttpServlet {

//Initialize global variables
public void init(ServletConfig config) throws ServletException {
super.init(config);
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
CMCommand = request.getParameter("CMCmnd");
CMUsername = request.getParameter("CMusrnm");
CMAuthToken = request.getParameter("CMAthTkn");
CMFirstName = request.getParameter("CMFN");
CMLastName = request.getParameter("CMLN");


and I want to pass these parameters to class called parameters in file parameters.java.

public class parameters

//variables
...
//constructor
...
//set and get methods
...

//main
public static void main(String[] argv)
...

parameters pm = new parameters();
//perform some operations on parameters
//passed by the servlet here.
 
> parameters pm = new parameters();
>//perform some operations on parameters
>//passed by the servlet here.

pm.setCommand( CMCommand);
// more of the same I guess?


-pete
 
I am a java newbie, so the servlet and the java file have to be in the same package and parameter.java should import that package. Am I correct here?

Another question can I just instantiate the parameter oject in servlet like this
parameters pm = new parameters("a", "b", "c");
//perform some operations on parameters
//passed by the servlet here.

and then assign values in in parameters.java like this?

public static void main(String[] argv)
foo = pm.setUsername();


 
> so the servlet and the java file have to be in the same package and
> parameter.java should import that package. Am I correct here?

No, the class code for 'parameter' can be in the same file, actually it can be nested inside the Servlet class.

-pete
 
correct me here if I am wrong. I am implementing a SOAP client so I dont want want to nest this class in servlet, it gets messy!

So, the problem is this, I want to pass parameters from servlet, to another class in parameter.java, which implements a SOAP client using an instance of parameter class, see the code below

parameters pm = new parameters();
//perform some operations on parameters
//passed by the servlet here.

thanks for your help

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top