aspose file tools*
The moose likes Struts and the fly likes logic:forward problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:forward problem" Watch "logic:forward problem" New topic
Author

logic:forward problem

Ingoba Ningthoujam
Ranch Hand

Joined: Dec 04, 2006
Posts: 90
My code is

<logic:notPresent name="catagory" scope="request">
<logic:forward name="cat"/>
</logic:notPresent>


<html-el:select property="category" value="">
<html-el ption value="0">Select Category</html-el ption>
<logic resent name="catagory" scope="request">
<c:forEach var="i" varStatus="status" items="${catagory}">
<html-el ption value="${i}">${i}</html-el ption>
</c:forEach>
</logic resent>
</html-el:select>

lobal forward

<forward name="cat" path="/web/category1.do" />
Action

<action path="/category1"
input="/Buyer/rfqview.jsp"
type="com.manipal.struts.action.Catalogue"/>

Catalogue class

package com.manipal.struts.action;
import com.manipal.struts.DataBase.DBConnect;
import java.util.Hashtable;
import java.util.Vector;
import org.apache.struts.action.*;
import java.sql.*;
import javax.servlet.http.*;

public class Catalogue extends Action
{
Connection con;


public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest req,HttpServletResponse res) throws Exception
{
Hashtable v=new Hashtable();
ResultSet r;
Statement st;
String path="";
int i=0;
Integer in;
con=DBConnect.getConnectionDB();
String param=req.getParameter("option");
System.out.println(DBConnect.i);
String s="select * from gil_category";
try
{
st=con.createStatement();
r=st.executeQuery(s);
while(r.next())
{
i=r.getInt("CATEGORYID");
in=new Integer(i);
v.put(in,r.getString("CATEGORY"));

}
req.setAttribute("catagory",v);
path="success";
}
catch (SQLException e)
{
System.out.println("Query not executed");
}
if(param.equals("view"))
return mapping.findForward(path);
else
return mapping.getInputForward();

}


}


Error:

SEVERE: ServletException in �WEB-INF/tiles/rfqpost.jsp� : Exception Forwarding for name cat : java.lang.IlligalState Exception : cannot forward after the response has been commiteed.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
What this message is telling you is that you have started to write something to the response in your JSP prior to the <logic:forward> tag, and that is not allowed. The <logic:notPresent> block that you have shown us must go at the very beginning of the JSP before writing anything -- even before the <head> block.


Merrill
Consultant, Sima Solutions
Ingoba Ningthoujam
Ranch Hand

Joined: Dec 04, 2006
Posts: 90
I am using tiles.

My files are: postrfq.jsp
<%@ taglib uri="/WEB-INF/struts-tiles.tld"
prefix="tiles" %>
<tiles:insert page="/WEB-INF/tiles/main-layout.jsp">
<tiles ut name="title" value="Welcome kurlon eprocurement system"/>
<tiles ut name="header" value="/WEB-INF/tiles/header2.jsp"/>
<tiles ut name="menu" value="/WEB-INF/tiles/search-menu.jsp"/>
<tiles ut name="body" value="/WEB-INF/tiles/rfqpost.jsp"/>
<tiles ut name="footer" value="/WEB-INF/tiles/footer.jsp"/>
</tiles:insert>


mainLayout.jsp

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>
<html:base />
<title><tiles:getAsString name="title" /></title>
</head>
<body><center>
<table border="0" width="80%" height="100%" cellspacing="5">
<tbody>
<tr><td colspan="2" height="20%" align="center"><tiles:insert attribute="header" /></td></tr>
<tr>
<td width="20%" height="75%" valign="top"><tiles:insert attribute="menu" /></td>
<td width="60%" height="75%" valign="top"><tiles:insert attribute="body" /></td>
</tr>
<tr><td colspan="2" height="5%" align="center"><tiles:insert attribute="footer" /></td></tr>
</tbody>
</table></center>
</body>
</html:html>

rfqpost.jsp

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="c.tld" prefix="c" %>
<%@ page language="java" %>
<%response.setHeader("Cache-Control","no-cache");
response.setHeader("Cache-Control","no-store");
response.setHeader("Location", "login.jsp");
response.setHeader("Pragma", "no-cache");
%>
<html:html>
<logic:notPresent name="id" scope="catagory">
<logic:forward name="cat"/>
</logic:notPresent>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript" src="../javascript/datetimepicker.js"></script>
<script language="javascript" type="text/javascript" src="../javascript/date.js"></script>
<style type="/web/text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
-->
</style>

</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="boder">
<tr>
<td height="1003" align="left" valign="top">
<br>
<html:errors/>
<html:form method="post" action="/postrfq.do" >
<table width="489" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td height="34" colspan="2" align="left" valign="middle"><div align="center"><span class="suppliers"><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=3><b>RFQ Posting Form</b></font></span></div><br/><div align="right"><font color="red">*</font> <FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2>Indicate mandatory fields</font></div></td>
</tr>
<tr>
<td width="205" height="34" align="left" valign="middle" class="headingsinforms"><strong> <B><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2>Category</FONT><font face="Verdana, Arial, Helvetica, sans-serif" color="red">*</font></B></strong></td>
<td width="278">
<% System.out.println("\n\n\nHI\n\n\n\n"); %>



<html-el:select property="category" value="">
<html-el ption value="0">Select Category</html-el ption>

</html-el:select>
</td>
</tr>
<tr>
<td height="32" align="left" valign="middle" class="headingsinforms"><strong><B><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2>Subcategory</FONT></B><font color="red">*</font></strong></td>
<td>
<html:select property="catsubcatid" value="">
<html ption value="0">Select SubCategory</html ption>

</html:select>
</td>
</tr>

<tr>
<td height="31" align="left" valign="middle" class="headingsinforms"><strong><B><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2>Product</FONT></B><font color="red">*</font></strong></td>
<td>
<html:select property="product" value="">
<html ption value="0">Select Product</html ption>

</html:select>
</td>
</tr>

<tr>
<td height="30" align="left" valign="middle" class="headingsinforms"><B><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Technical
Specification</FONT></B><font color="red">*</font></td>
<td><html:textarea property="techspec" rows="3"/></td>
</tr>
<tr>
<td height="30" align="left" valign="middle" class="headingsinforms"><B><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Product
Description </FONT></B></td>
<td><html:textarea property="description" rows="3"/></td>
</tr>
<tr>
<td height="28" align="left" valign="middle" class="headingsinforms"><strong><B><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Delivery
Destination</FONT></B><font color="red">*</font></strong></td>
<td>

<html:select property="location" >
<html ption value="0">Select One</html ption>



</html:select>


</td>
</tr>
<tr>
<td height="28" align="left" valign="middle" class="headingsinforms"><B><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2>Quality</FONT></B></td>
<td><html:textarea property="quality" rows="3"/> </td>
</tr>
<tr>
<td height="28" align="left" valign="middle" class="headingsinforms"><strong> <B><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Mode of
Shipment</FONT></B><font color="red">*</font> </strong></td>
<td>
<html:select property="shipmentmode" >
<html ption value="selected">Select Shipment</html ption>
<html ption value="Air">Air</html ption>
<html ption value="Sea">Sea</html ption>
<html ption value="Surface Road">Surface Road</html ption>
<html ption value="Surface Rail">Surface Rail</html ption>
</html:select>
</td>
</tr>

<tr>
<td height="26" align="left" valign="middle" class="headingsinforms"><strong><B><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Package
Details</FONT></B><font color="red">*</font></strong></td>
<td><html:textarea property="packagedet" rows="3"/></td>
</tr>
<tr>
<td height="27" align="left" valign="middle" class="headingsinforms"><strong><B><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2>Photograph</FONT></B></strong></td>
<td><html:textarea property="photo1" rows="3"/></td>
</tr>
<tr>
<td height="30" align="left" valign="middle" class="headingsinforms"><B><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2>Remarks</FONT></B></td>
<td><html:textarea property="remark1" rows="3"/></td>
</tr>
<tr>
<td height="27" align="left" valign="middle" class="headingsinforms"><B><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2>Photograph</FONT></B></td>
<td><html:file property="photo2" size="20"/></td>
</tr>
<tr>
<td height="29" align="left" valign="middle" class="headingsinforms"><B><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2>Remarks</FONT></B></td>
<td><html:textarea property="remark2" rows="3"/></td>
</tr>
<tr>
<td height="31" align="left" valign="middle" class="headingsinforms"><strong><B><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Target
Price</FONT></B><font color="red">*</font></strong></td>
<td><html:text property="expprice" size="20"/>
<html:select property="exppricetype" value="">
<html ption value="0">Select Target </html ption>

</html:select>
</td>
</tr>

<tr>
<td height="61" align="left" valign="middle" class="headingsinforms"><B><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Delivery
Terms</FONT></B><font color="red">*</font></td>
<td><html:radio property="price_term" value="FDF" >
<FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Free Delivery
to Factory</FONT></html:radio><br>
<html:radio property="price_term" value="EYW">
<FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Ex-Your-Works</FONT></html:radio></td>
</tr>
<tr>
<td height="61" align="left" valign="middle" class="headingsinforms"><strong><B><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>Payment
Terms</FONT></B><font color="red">*</font></strong></td>
<td><html:textarea property="paymentterm" rows="3"/></td>
</tr>

<tr>
<td height="59" align="left" valign="middle" class="headingsinforms"><strong><B><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=2>End date
for Submission of Qtn </FONT></B></strong></td>
<td><html:text property="enddate" size="30" maxlength="10" readonly="readonly" value=""/>
<a href="javascript:NewCal('date','ddmmyyyy')"><img src="../images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
</tr>
</table>
<br>
<br>
<img src="../forms/supplier_files/mb.gif" width="1" height="16">
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr> <td>
<input type="hidden" name="newaccount" value="second">
<html:submit property="submit1" value="Next>>"/></td>
<td><html:reset property="Submit2" value="Reset"/></td>
</tr>
</table>
<br>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>


I am getting the same error.pliz help me.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm afraid you simply can't do what you're trying to do in this way.

Tiles takes several page fragments and of those fragments, generates a single http page to send back to the browser. The principle behind a redirect is that you decide "up front" that this is not the page you should be displaying, but some other page. If you try to do this inside a tile (which, remember is a page fragment) you have already tried to send part of your response to the browser. You can't change your mind in mid-stream.

I haven't used tiles a lot, so don't know all the tricks, but here is something I think would work:

Put the following code in your postrfq.jsp:

and remove the <logic:notPresent> block from rfqpost.jsp.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: logic:forward problem