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

how do i use html:select to forward to different pages?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi , i need to know that, what do i need to edit in the action class or if here to route my page according to the option i select from the html:option.
i am a newbie so little help will be required.
Do i need to edit anythin in the action class..? or do ihave to do it here??






JSP PAGE


<%@ 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="WEB-INF/tlds/struts-html" prefix="html"%>
<%@ taglib uri="WEB-INF/tlds/struts-logic" prefix="logic"%>
<%@ taglib uri="WEB-INF/tlds/struts-bean" prefix="bean"%>

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1 align="center"><u>Table 1</u></h1>
<html:form action="/hello" method="post" >
<table id="cs1" width="" border="0" align="center" bgcolor="white" >
<tr>
<th align="center">
Name<html:text property="Name" />
</th>
</tr>
<tr>
<th align="center">From Date <html:text property="fromDate" /></th>
</tr>
<tr>
<th align="center" >
To Date <html:text property="toDate" />
</th>
</tr>
<tr>
<th align="center" >
Type<html:select property="Type" size="1" >
<html:option value="0">A </html:option>
<html:option value="1">B</html:option>
<html:option value="2">C</html:option>
</html:select>
</th>
</tr>
<tr>
<th align="center">
2Name<html:select property="2Name" size="1" >
<html:option value="0"> J2</html:option>
<html:option value="1"> J1</html:option>
<html:option value="2"> J3</html:option>
</html:select>
</th>
</tr>

<tr></tr>
<tr>
<th>
<html:submit />

</th>
</tr>



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




ACTION CLASS


package ui.web.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;


import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
public class CommonServicesAction extends Action{public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception
{
return mapping.findForward("success3");
}}




Struts config

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>


<!-- ========== Form Bean Definitions ============ -->
<form-beans>

<form-bean name="HelloForm" type="ui.web.struts.action.HelloForm" />


</form-beans>







<!-- ========== Action Mapping Definitions ======== -->
<action-mappings>
<action
path="/hello"
type="ui.web.struts.action.helloAction"
name="HelloForm"
scope="session"
validate="true"
>
<forward name="success3" path="/hellohello.jsp" />
</action>
</action-mappings>

</struts-config>




Action FORM

import org.apache.struts.action.*;
public class CommonServicesForm extends ActionForm{
private String Name=null;
private Object fromDate=null;
private Object toDate=null;
private String Type;
private String 2Name;
public void setFromDate(Object fromDate) {
this.fromDate = fromDate;
}
public Object getFromDate() {
return this.fromDate;
}
public void setName(String Name) {
this.Name = Name;
}
public String getName() {
return this.Name;
}
public void setToDate(Object toDate) {
this.toDate = toDate;
}
public Object getToDate() {
return toDate;
}
public void setType(String Type) {
this.Type = Type;
}
public String getType() {
return Type;
}
public void set2Name(String 2Name) {
this.2Name = 2Name;
}
public String get2Name() {
return 2Name;
}
}

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pratik,

You can use javascript to forward to a new page. All that you need to do is that onchange call a javascript function that forwards the request to a different page. eg

<script>
function forward(val){
window.location.href=val
}
</script>

<select name="hjh" onchange="forward(this.value)">
<option value="index.html" >M</option>
<option value="menu.html" >N</option>
</select>





 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use requestDispatcher class. Retrieve value and forward to page according to you .
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean you want to submit the form and select the ActionForward based on the value in the dropdown? Just return a different ActionForward based on form value. ActionForwards can also be created from URLs.

When you post code please (a) disable smilies, and (b) put it in code tags:

/

so the code remains formatted:


 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do this using js or you can forward it to a jsp page and based on the value selected you can forward to different jsp pages using jsp:forward.

regards
Struts Developer
 
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic