File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes IDEs, Version Control and other tools and the fly likes Help me writing an ACTION class in eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Help me writing an ACTION class in eclipse" Watch "Help me writing an ACTION class in eclipse" New topic
Author

Help me writing an ACTION class in eclipse

sagar podilapu
Greenhorn

Joined: Feb 25, 2009
Posts: 13
Hi guys,
i have a question here.
Could some one show me how to work it out.

"Create a JSP called Login.jsp and just to provide two text boxes
a username and password as shown below
Username:
Password:
Cancel Submit


Create an ACTION class. When you SUBMIT the values this action class should
Take those values and output to the console.
"

i have the code for first part.
"<HTML>
<HEAD>
<TITLE>Sending a request</TITLE>
</HEAD>
<BODY>
<FORM ACTION= METHOD="POST">
<BR><BR>
Username: <INPUT TYPE="TEXT" NAME="Username">
Password:<INPUT TYPE="TEXT" NAME="Password" >
<INPUT TYPE="SUBMIT" VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Cancel">
</FORM>
</BODY>
</HTML>
"

Action is empty here coz i dont have any cgi.
Thank You.


If nothing goes right
go left
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Please be sure to take the time to compose descriptiv e subjects for your posts; read this for more information.

A title such as "help me" is not helpful. What would happen if all posts had such a title?

Please go back and change your post to add a more meaningful subject by clicking the button on your post.

Also, please use real words when posting to the forums. Abbreviations such as "coz" in place of "because" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

"Action class" sounds like a Struts term. Is this homework for a class on Struts?
Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
sagar podilapu wrote:

Create an ACTION class. When you SUBMIT the values this action class should
Take those values and output to the console.
[/b]"


Well, you need something in the action field (I'd suggest another jsp) that this form is
directed to and it in turn prints out the parameters, or maybe I'm not understanding
your question?

sagar podilapu wrote:
i have the code for first part.
"<HTML>
<HEAD>
<TITLE>Sending a request</TITLE>
</HEAD>
<BODY>
<FORM ACTION= METHOD="POST">
<BR><BR>
Username: <INPUT TYPE="TEXT" NAME="Username">
Password:<INPUT TYPE="TEXT" NAME="Password" >
<INPUT TYPE="SUBMIT" VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Cancel">
</FORM>
</BODY>
</HTML>
"

Action is empty here coz i dont have any cgi.
Thank You.


er, you don't have any cgi? I certainly hope not!

[SCJP 6]
[SCBCD in process]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Karl Krasnowsky wrote:I'd suggest another jsp

I would not. JSPs are units of view, not processing. The target of a form submission should be a servlet.

The mention of CGI confuses me though. Why post about CGI in a forum on JSPs?
sagar podilapu
Greenhorn

Joined: Feb 25, 2009
Posts: 13
hey thank you guys.
I m sorry for mentioning CGI.
I have written a servlet class named LoginDemo and i pointed my action to this class.
I have written the code but when i m trying to run the program,it gives several errors.
my code is as follows...
"
package javax.servlet.http;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class LoginDemo extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Obtaining the Query String</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("Query String: " + request.getQueryString() + "<BR>");
out.println("<FORM METHOD=GET>");
out.println("<BR>Username: <INPUT TYPE=TEXT NAME=Username>");
out.println("<BR>Password: <INPUT TYPE=TEXT NAME=Password>");
out.println("<BR><INPUT TYPE=SUBMIT VALUE=Submit>");
out.println("<BR><INPUT TYPE=RESET VALUE=Cancel>");
out.println("</FORM>");
out.println("</BODY>");
out.println("</HTML>");
}
}"


The following are the errors
"
The import javax.servlet.ServletException cannot be resolved
The import javax.servlet.http.HttpServletResponse cannot be resolved
The import javax.servlet.http.HttpServletRequest cannot be resolved
The import javax.servlet.http.HttpServlet cannot be resolved
ServletException cannot be resolved to a type
HttpServletResponse cannot be resolved to a type
HttpServletRequest cannot be resolved to a type
HttpServlet cannot be resolved to a type

"

Please Comment on it.
Thank You.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Still waiting for you to adjust your topic title.
sagar podilapu
Greenhorn

Joined: Feb 25, 2009
Posts: 13
i ll change it if i know it..
someone can help me to change this topic name please..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Those aren't run-time errors, they're compile-time errors.

You need to make sure that the Servlet API classes are on the classpath when you compile the servlet.
sagar podilapu
Greenhorn

Joined: Feb 25, 2009
Posts: 13
@Bear Bibeault

Thank You.
Could you explain how to check that.
I am new to JAVA and related topics.
I am sorry if i have asked help for an easy task.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

How are you trying to compile the servlet?
sagar podilapu
Greenhorn

Joined: Feb 25, 2009
Posts: 13
I m using eclipse 3.4.1.
It doesnt allow me to compile as there are some errors.
Thank You.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

sagar podilapu wrote:I m using eclipse 3.4.1.

OK, I've moved this over to the IDEs forum where eclipse issues are dealt with.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

Is j2ee.jar or servlet-api.jar in the classpath for the Java project?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sagar podilapu
Greenhorn

Joined: Feb 25, 2009
Posts: 13
Let me Explain what i have done.

In eclipse 3.4.1,i went into Buildpath>>Configure Buildpath>>Projects>>add.
I couldnt fine my project overthere to add to a classpath.
Thid is the only error i came across when i run my program on tomcat server.
it says
type Status report

message /SagarIVRApp/ACTION.java

description The requested resource (/SagarIVRApp/ACTION.java) is not available.



I will provide my entire program.
Can someone help me
Can someone compile it in eclipse and figure t out please.

My Login.JSP

"
<HTML>
<HEAD>
<TITLE>Login</TITLE>
</HEAD>
<BODY>
<FORM ACTION = "ACTION.java" METHOD="POST">
<BR><BR>
Username: <INPUT TYPE="TEXT" NAME="Username"><BR>
Password:<INPUT TYPE="TEXT" NAME="Password" ><BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Cancel">
</FORM>
</BODY>
</HTML>
"

My ACTION.java
"package Com.kronsys.xxxx;
public class ACTION {
String Username;
String Password;
public void SetUsername(String value)
{
Username=value;
}
public void SetPassword(String value)
{
Password=value;
}
public String GetUsername(){
return Username;
}
public String GetPassword(){
return Password;
}

}
"

This program is to write a JSP to get USERNAME AND PASSWORD and then to write and ACTION class to display the given username and password.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help me writing an ACTION class in eclipse