Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

struts simple program

 
Greenhorn
Posts: 25
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone tell me wat s the problem in this...... i am gettin an error like this
error.jpg
[Thumbnail for error.jpg]
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ganapathy,

Check this,

Have you specified the form and its action mapping correctly in your struts-config.xml file ?

Post your JSP file for quick response
 
N. Ganapathy
Greenhorn
Posts: 25
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This s my login.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" 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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>LOGIN FORM</h1><table border="1" width="0">
<thead>
<tr>
<td colspan="2">
<bean:write name="LoginForm" property="error" filter="false"/>
 </td>
</tr>

<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">
<bean:write name="LoginForm" property="error" filter="false"/>
 </td>
</tr>

<tr>
<td>ENTER YOUR NAME:</td>
<td><html:text property="name" /></td>
</tr>
<tr>
<td>ENTER YOUR EMAIL ID:</td>
<td><html:text property="email"/></td>
</tr>
<tr>
<td></td>
<td><html:submit value="Login" /></td>
</tr>
</tbody>
</table>

<html:form action="/login">

<html:submit value="Login" />

</html:form>
</body>
</html>

this s my success.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" 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=UTF-8">
<title>LOGIN SUCCESS</title>
</head>
<body>
<h1>Congratulations!</h1>

<p>You have successfully logged in.</p>

<p>Your name is: .</p>

<p>Your email address is: .</p>
<p>Your name is: <bean:write name="LoginForm" property="name" />.</p>

<p>Your email address is: <bean:write name="LoginForm" property="email" />.</p>

</body>
</html>

this s my struts.config

<struts-config>
<form-beans>
<form-bean name="LoginForm" type="com.myapp.struts.LoginForm"/>


</form-beans>

<global-exceptions>

</global-exceptions>

<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>

<action-mappings>
<action name="LoginForm" path="/login" scope="request" type="com.myapp.struts.LoginAction" validate="false">
<forward name="success" path="/WEB-INF/success.jsp"/>
<forward name="faiilure" path="/login.jsp"/>
</action>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
</action-mappings>

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

<message-resources parameter="com/myapp/struts/ApplicationResource"/>


<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>

<!-- ========================= Validator plugin ================================= -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>

this s my action class

package com.myapp.struts;

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.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
*
* @author Administrator
*/
public class LoginAction extends org.apache.struts.action.Action {

/* forward name="success" path="" */
private final static String SUCCESS = "success";
private final static String FAILURE = "failure";


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginForm formBean = (LoginForm)form;
String name = formBean.getName();
String email = formBean.getEmail();

if((name == null) || // name parameter does not exist
email == null || // email parameter does not exist
name.equals("") || // name parameter is empty
email.indexOf("@") == -1) { // email lacks '@'


return mapping.findForward(FAILURE);}
else
{ return mapping.findForward(SUCCESS);
}
}
}

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you write the Action Form been class LoginForm under com.myapp.struts package?
 
N. Ganapathy
Greenhorn
Posts: 25
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i have written both LoginAction.java and LoginForm.java in com.myapp.struts ...

This is my LoginForm.java

package com.myapp.struts;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class LoginForm extends org.apache.struts.action.ActionForm {

private String name;
private String email;
private String error;

public String getError() {
this.error = "<span style='color:red'>Please provide valid entries for both fields</span>";
return error;
}

public void setError(String error) {
this.error = error;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

private int number;

public String getName() {
return name;
}

public void setName(String string) {
name = string;
}

public int getNumber() {
return number;
}

public void setNumber(int i) {
number = i;
}
public LoginForm() {
super();
}

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (getName() == null || getName().length() < 1) {
errors.add("name", new ActionMessage("error.name.required"));
}
return errors;
}
}
 
venkataswamy sonti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think problem with your login.jsp page.. Try the following code...

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" 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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<html:form action="/login">
<h1>LOGIN FORM</h1><table border="1" width="0">
<thead>
<tr>
<td colspan="2">
<bean:write name="LoginForm" property="error" filter="false"/>
</td>
</tr>

<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">
<bean:write name="LoginForm" property="error" filter="false"/>
</td>
</tr>

<tr>
<td>ENTER YOUR NAME:</td>
<td><html:text property="name" /></td>
</tr>
<tr>
<td>ENTER YOUR EMAIL ID:</td>
<td><html:text property="email"/></td>
</tr>
<tr>
<td></td>
<td><html:submit value="Login" /></td>
</tr>
</tbody>
</table>



<html:submit value="Login" />

</html:form>
</body>
</html>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic