Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

by using struts running servlet and jsp in tomcat

843838Nov 21 2005 — edited Nov 21 2005
hi everybody,
pls solve this problem,i have give detailed information

--> i have a servlet file namd Form.java

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class Form extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

ServletOutputStream sos=response.getOutputStream();
String fname=request.getParameter("firstname");
String lname=request.getParameter("lastname");
String dob=request.getParameter("dob");
String uid=request.getParameter("uid");
String pwd=request.getParameter("pwd");
sos.println("First Name = " + fname +" "+lname+"<br>");
sos.println("DOB = " + dob);
sos.println("Username = " + uid);
sos.println("password = " + pwd);

String target = new String("success");
return (mapping.findForward(target));
}
}



-->jsp file named form.jsp
<html>
<body>
exe on httpservlet
<form action="http://localhost:8080/satish/Form">
enter firstname <input type= "text" name="firstname"><br>
enter lastname <input type="text" name="lastname"><br>
enter DateofBirth <input type="text" name="dob"><br>
enter userid <input type="text" name="uid"><br>
enter password <input type="text" name="pwd"><br>
<input type="submit" value="register">
</form>
</body>
</html>

and i have web.xml in F:\projects\tomcat\webapps\satish\WEB-INF
with below contents

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>struts example</display-name>
<description>
Mycode
</description>

<!--GENERATED_JSPS-->


<!-- JSPC servlet mappings start -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class> org.apache.struts.action.ActionServlet </servlet-class>
<init-parameter>
<name>application</name>
<value>ApplicationResources</value>
</init-parameter>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action </servlet-name>
<url-pattern>/satish/Form</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->
</web-app>



and struts-config.xml file in F:\projects\tomcat\webapps\satish
with below contents

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" >
<struts-config>
<action-mappings>
<action path="/form" type="Form" input="/form.jsp" >
</action>
</action-mappings>
</struts-config>

and run the tomcat server
typed http://localhost/satish/form.jsp
given the input and clicked submit button and i got
this
HTTP Status 404 - /satish/Form

--------------------------------------------------------------------------------

type Status report

message /satish/Form

description The requested resource (/satish/Form) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.5
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 19 2005
Added on Nov 21 2005
8 comments
404 views