• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to get the values in action class

 
Ranch Hand
Posts: 53
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
these are classes i have created but my application is not working properly ,as the value passed in jsp page is not accessible in action class?

somebody please tell me why the txtName is not accessible in the bean class,which was passed in the index.jsp ?

index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<html:form action="/Login">
<html:text property="" value="" name="txtName"></html:text>
<html:submit value="submit"></html:submit>
</html:form>
</body>
</html>

------------------------------------------------------------------------------------
Success.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
</head>
<body>
success........
</body>
</html>

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

Failure.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
</head>
<body>
failure
</body>
</html>
-----------------------------------------------------------------------

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>

<form-beans>
<form-bean name="LoginBean" type ="com.model.LoginModel"/>
</form-beans>

<global-forwards>

<forward name="" path="" />
</global-forwards>

<action-mappings>

<action name="LoginBean" path="/Login" type="com.action.LoginAction" scope="request">
<forward name="success" path="/Success.jsp" />
<forward name="failure" path="/Failure.jsp" />
</action>

</action-mappings>

<message-resources parameter="com.cts.eShopAdmin.properties.ApplicationResource" />

<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>


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

LoginAction

package com.action;
import com.model.*;

import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.jasper.tagplugins.jstl.core.Out;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
* Servlet implementation class LoginAction
*/
public class LoginAction extends Action implements Servlet {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
LoginModel loginModel=(LoginModel)form;
if(loginModel.getTxtName()=="arun")
return mapping.findForward("success");
else
{
System.out.print(loginModel.getTxtName());
return mapping.findForward("failure");
}



}

/**
* @see Action#Action()
*/
public LoginAction() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
}

/**
* @see Servlet#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}

/**
* @see Servlet#getServletConfig()
*/
public ServletConfig getServletConfig() {
// TODO Auto-generated method stub
return null;
}

/**
* @see Servlet#getServletInfo()
*/
public String getServletInfo() {
// TODO Auto-generated method stub
return null;
}

/**
* @see Servlet#service(ServletRequest request, ServletResponse response)
*/
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}


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

LoginModel

package com.model;

import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.struts.action.ActionForm;

/**
* Servlet implementation class LoginModel
*/
public class LoginModel extends ActionForm implements Servlet {

/**
*
*/
private static final long serialVersionUID = 1L;

/**
* @see ActionForm#ActionForm()
*/
public String txtName=null;
public String getTxtName() {
return txtName;
}

public void setTxtName(String txtName) {
System.out.print(txtName);
this.txtName = txtName;
}

public LoginModel() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
}

/**
* @see Servlet#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}

/**
* @see Servlet#getServletConfig()
*/
public ServletConfig getServletConfig() {
// TODO Auto-generated method stub
return null;
}

/**
* @see Servlet#getServletInfo()
*/
public String getServletInfo() {
// TODO Auto-generated method stub
return null;
}

/**
* @see Servlet#service(ServletRequest request, ServletResponse response)
*/
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}




somebody please tell me why the txtName is not accessible in the bean class,which was passed in the index.jsp ?

from

phooton misra
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Please put the value in the property feild and by the time please refer this example which will help you..
http://www.mkyong.com/struts/struts-htmltext-textbox-example/

Regards
Jatan
 
phooton misra
Ranch Hand
Posts: 53
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank jatan for your valuable suggestion ,its working now....................
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic