• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Looking for Struts and Weblogic Example

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm trying to understand Struts. Most of the examples I see are using other servers. Does anyone have a simple example that works on Weblogig 6.0? Simpler the better, I'm just starting.
Steve
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
here is a simple example which involves two JSP, two form classes and an action class.Index jsp is loaded first. here you key in the username and click the ok button. it takes you to the other jsp named Accept.jsp which displays the user name. In the backend, when you click the button on index.jsp, the value of username is taken to the form bean and in the action class the data from the form bean of Index.jsp is retrieved and stored in the form bean of the Accept.jsp and the jsp is loaded. It automatically gets the data from the form bean and displays it on the Accept.jsp.
The following are the codes.
code of index.jsp..
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
<title>FIrst Example</title>
<html:base/>
</head>
<body bgcolor="white">
<html:errors/>
<html:form action="Index.do" focus="username" name="indexForm" type="testing.IndexForm">
<table border="0" width="100%">
<tr>
<th align="right">
Give Your Name
</th>
<td align="left">
<html:text property="username" size="16" maxlength="16"/>
</td>
</tr>
<tr>
<td align="right">
<html:submit property="submit" value="OK"/>
</td>
</tr>
</table>
</html:form>
</body>
</html>
code for accept.jsp
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<html:form action="" focus="output" name="AcceptForm" type="testing.AcceptForm">
<table border="0" width="100%">
<tr>
<th align="right">
Give Your Name
</th>
<td align="left">
<html:text property="output" size="16" maxlength="16"/>
</td>
</tr>
<tr>
<td align="right">
<html:submit property="submit" value="OK"/>
</td>
</tr>
</table>
</html:form>
</BODY>
</HTML>
code for the action class IndexAction
package testing;
import javax.servlet.http.*;
import javax.servlet.*;
import org.apache.struts.action.*;
import java.io.IOException;
public final class IndexAction extends Action {
public ActionForward perform (ActionMapping mapping,ActionForm form ,HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
String username = ((IndexForm)form).getUsername();
AcceptForm acptform = new AcceptForm();
acptform.setOutput(username);
HttpSession session = request.getSession();
session.setAttribute("AcceptForm",acptform);
return mapping.findForward("success");
}
}
code for index form
package testing;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;

public final class IndexForm extends ActionForm{
private String username="subhendu";
public IndexForm()
{
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username=username;
}
}
code for acceptform
package testing;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;

public final class AcceptForm extends ActionForm{
private String output;
public AcceptForm()
{
}
public String getOutput()
{
return output;
}
public void setOutput(String output)
{
this.output="from accept bean"+output;
}
}
entry in action.xml
<action-mappings>
<action path="/Index"
actionClass="testing.IndexAction"
formAttribute="indexForm"
formClass="testing.IndexForm"
scope="session"
inputForm="/index.jsp"
validate="true">
<forward name="success" path="/Accept.jsp"/>
</action>
</action-mappings>
 
Saloon Keeper
Posts: 25466
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no reason I know of that prevents a generic struts WAR from being executable under WebLogic. I think WebSphere needed a little assistance, though.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used the same example and tried to implement it. I was able to get the index.jsp to render, however, when I press the <ok> button, I get the following error message:
<Jan 16, 2003 3:46:10 PM EST> <Error> <HTTP> <[WebAppServletContext(6821348,wrox-struts,/wrox-struts)] Servlet failed with Exception
java.lang.NullPointerException
Does anyone know the reason for this???
Thanks.
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic