aspose file tools*
The moose likes Struts and the fly likes how do i use html:select to forward to different pages? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how do i use html:select to forward to different pages?" Watch "how do i use html:select to forward to different pages?" New topic

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

pratik mehta

Joined: Jan 28, 2009
Posts: 3

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 htmlption.
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??


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<%@ 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"%>


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

<html:submit />




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"

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

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


<!-- ========== Action Mapping Definitions ======== -->
<forward name="success3" path="/hellohello.jsp" />


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;

Praveen Sangolli

Joined: May 22, 2008
Posts: 28
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

function forward(val){

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

rahulash sharma

Joined: Jan 05, 2009
Posts: 15
You can use requestDispatcher class. Retrieve value and forward to page according to you .
David Newton

Joined: Sep 29, 2008
Posts: 12617

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:

Nyanas Kandhan
Ranch Hand

Joined: Jan 27, 2009
Posts: 35
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.

Struts Developer

I agree. Here's the link:
subject: how do i use html:select to forward to different pages?