• 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

form values not showing in jsp

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I have a simple jsp where I am displaying 2 columns using html:text and c tag. When the jsp is displayed, the form values are not being populated.

I have a system.out.println() in action class and its not showing in the console. I don't know what I'm doing wrong.

I'm running this in tomcat

Here is the code snippet

jsp: aa.jsp - is in webapps\root folder

<html:form action="TestAction">
<c ut value="${role}"/>
<html:text property="jobMessage"/>
</html:form>

struts-config.xml - which is under WEB-INF

<form-beans>
<form-bean name="testForm" type="com.test.TestForm"/>
</form-beans>

<action path="/aa"
type="com.test.TestAction"
scope="request"
name="testForm">
<forward name="success" path="/aa.jsp"/>
</action>

TestAction.class and TestForm.class are under WEB-INF\classes\com\test

TestAction

public class TestAction extends Action {

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {

System.out.println("enter");

List jobList = new ArrayList();
RunJob job = new RunJob();
job.setJobId("1");

jobList.add(job);

String msg = null;

if(jobList.size() == 0) {
msg = "There are no runjobs";
} else {
msg = jobList.size() + " runjob(s) are in the queue";
}

// set form values
TestForm testForm = (TestForm) form;
String role = "admin";

testForm.setRole(role);
testForm.setMsg(msg);

return mapping.findForward("success");
}
}


Form

public class TestForm extends ActionForm {

private String role;
private String msg;

public String getRole() {
return role;
}

public void setRole(String role) {
this.role = role;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
}

Thanks in advance.
p pro
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have an action definition in struts-config with a path of "/TestAction"? The html:text tag will use the form bean (name property) of the enclosing html:form tag.

Your c:out tag probably needs to use "testForm.role". (I tend to use the bean:write tag just because I know it...<bean:write name="testForm" property="role" />).

- Brent
 
Pam Theod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this in struts-config.xml

<action path="/aa" type="com.test.TestAction" scope="request" name="testForm">
<forward name="success" path="/aa.jsp"/>
</action>

Should I define action class like I did with TestForm

How do I do that.

Also, I have a question. When the jsp opens, on load will it find the action from the action mapping defined in struts-config and run execute method. I want to know when will execute method get executed.

Thanks in advance.

P pro
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have lines like this in your JSP?

<%@ taglib prefix="html" uri="/tags/struts-html" %>
<%@ taglib prefix="c" uri="/tags/jstl-core" %>

When you specify the <html:form> tag, you are specifying the action that will get called when you submit the form. It might be helpful to use realistic names for you action, forms and jsp pages. Like SaveUser, UserForm and UserDetails.jsp.

- Brent
 
Pam Theod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brent,
I finally figured the problem .I was using Action instead of DispatchAction. Thanks for all your suggestions.

Thanks,
P pro
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic