Sam mit

Greenhorn
+ Follow
since Sep 11, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sam mit

Thanks ayyappan Bas,
Its working now.
12 years ago
login.jsp

web.xml


home.jsp


loginBean.java



loginAction.java


in LoginAction.java class.. i put the comment on the error line..
Please suggest me...
12 years ago
Hi,
I wrote one simple struts program for login page.

struts-config.xml:--------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE struts-config SYSTEM "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>
<form-beans >
<form-bean name="loginBean" type="com.sam.bean.loginBean" />
</form-beans>

<action-mappings>
<action path="/login" name = "loginBean" type = "com.sam.action.loginAction"
scope= "request" input="/login.jsp">
<forward name="success" path="/home.jsp"></forward>
<forward name="failure" path="/login.jsp"></forward>
</action>
</action-mappings>

<!-- <message-resources parameter="MessageResources" /> -->
</struts-config>


login.jsp:--------------------

<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Page</title>
</head>
<body>
<html:form action="/login.do">
<table>
<tr>
<td>User Id :</td>
<td><html:text property="text" name="userId"/></td>
</tr>

<tr>
<td>Password :</td>
<td><html:text property="password" name="password"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<html:submit value= "login" ></html:submit>
</td>
</tr>
</table>
</html:form>


</body>
</html>

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

home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome Struts Project </title>
</head>
<body>
<h1>Welcome Struts Project </h1>
<h1>
Hi <bean:write name ="userId" scope = "request"/>
</h1>

</body>
</html>

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

loginAction.java

package com.sam.action;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.sam.bean.loginBean;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class loginAction extends Action{

public ActionForward execute(ActionMapping am , ActionForm af,
HttpServletRequest req, HttpServletResponse res) throws Exception
{
loginBean lb = (loginBean)af;
String userId = lb.getUserId();
String password = lb.getPassword();

String str = "failure";
if(userId.equals(password))
{
str = "success";
req.setAttribute("userId", userId);
}

ActionForward aFwd = am.findForward(str);
return aFwd;
}

}

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

loginBean.java

package com.sam.bean;

import org.apache.struts.action.ActionForm;

public class loginBean extends ActionForm{

private String userId;
private String password;

public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}

}


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

web.xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE web-app SYSTEM "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<display-name>Struts Examples Application</display-name>
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<!-- module configurations -->

<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>

<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Usual Welcome File List -->

<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
<!-- tiles not used here
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
-->
</web-app>


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

Error getting:

url:http://localhost:8080/StrutsProject/login.do

HTTP Status 500 -

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

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:516)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause

java.lang.NullPointerException
com.sam.action.loginAction.execute(loginAction.java:23)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.30 logs.


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

Apache Tomcat/5.5.30



can anybody solve my problem?
Please tell me how to rum this program??

Thanks in advance
12 years ago