aspose file tools*
The moose likes Struts and the fly likes unable to get the values in action class ,passed in jsp page,which was stored in the bean ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Reply locked New topic
Author

unable to get the values in action class ,passed in jsp page,which was stored in the bean ?

phooton misra
Ranch Hand

Joined: Jul 31, 2012
Posts: 47

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: unable to get the values in action class ,passed in jsp page,which was stored in the bean ?