Hi,
I want to pass input parameter entered in the login page to
ActionSupport class. How to pass it.
I used httpservletreq object to get value, but getting NullPointerException
in the req.getParameter("submitvalue") line.
struts.xml :
<struts>
<package name="ActionServlet" namespace="/JSPPages"
extends="struts-default">
<action name="AJAX" class="com.cts.AJAX">
<result name="success">/JSPPages/AJAXSuccess.jsp</result>
<result name="failure">/JSPPages/AJAXFailure.jsp</result>
<result name="error">/JSPPages/AJAXError.jsp</result>
</action>
</package>
</struts>
Login page :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is my Struts2 and AJAX JSP</title>
</head>
<body>
<form action="JSPPages/AJAX.action">
<h2>This JSP page explains how Struts uses AJAX</h2><br>
Click the button to see the AJAX page...<br>
<input type="submit" value="Show AJAX Page" name="submitvalue"/>
<input type="submit" value="Show Failure Page"
name="submitvalue"/>
</form>
</body>
</html>
AJAX.java :
package com.cts;
import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpServletRequest;
public class AJAX extends ActionSupport {
HttpServletRequest req;
@Override
public String execute() throws Exception {
String submit_value = req.getParameter("submitvalue");
if (submit_value != null && submit_value.equalsIgnoreCase("Show AJAX
Page")) {
return "success";
} else if (submit_value != null &&
submit_value.equalsIgnoreCase("Show Failure Page")) {
return "failure";
}
System.out.println("Error occurred :: submit_value = " +
submit_value);
return "error";
}
}
Is it possible to use HttpServletRequest inside execute() method? What is
the problem in the above code? and what is the solution?
Thanks in advance,
--
View this message in context:
http://www.nabble.com/Pass-parameter-to-ActionSupport-class-tp22947415p22947415.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]