Home Answers Viewqa Struts Unable to understand Struts

 
 


Abhishek
Unable to understand Struts
0 Answer(s)      3 years ago
Posted in : Struts

I am studying in GNIIT from NIIT.
Here in 4th sem we have stuts also but I am not able to understand it.
I've made an application.That application is of book entry.
I have made the application but in that application when I enter the details of book, data base becomes updated but I did'nt get successfull msg.
it doesnat forwads on the success page.



package com.struts.controller;


import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import servlet.model.Book;
import servlet.model.BookService;

/**
*
* @author niit
*/
public class AddBookStruts extends org.apache.struts.action.Action {

/* forward name="success" path="" */
private static final String SUCCESS = "success";

/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception

{
PrintWriter out = response.getWriter();
try{

out.println("<a href='index.jsp'>Home Page</a>");
BookService bs=new BookService("C:\\data\\");

String strAuthor=request.getParameter("author");
String strPages=request.getParameter("pages");
String strDescription=request.getParameter("description");

int isbn=bs.AutoIncrement();
int pages=Integer.parseInt(strPages);

Book book=new Book(isbn,strAuthor,pages,strDescription);

bs.storeBook(book);

request.setAttribute("book",book);

return mapping.findForward(SUCCESS);
}

catch(Exception ex)
{
out.println(ex.toString());
}
finally
{

out.close();
}
return mapping.findForward("error");
}
}
---------------------------------------------------------------------------
package servlet.view;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import servlet.model.Book;
import servlet.model.BookService;

/**
*
* @author niit
*/
public class AddBookServlet extends HttpServlet {

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try
{
out.println("<a href='index.jsp'>Home Page</a>");

BookService bs=new BookService("C:\\data\\");

String strAuthor=request.getParameter("author");
String strPages=request.getParameter("pages");
String strDescription=request.getParameter("description");

int isbn=bs.AutoIncrement();
int pages=Integer.parseInt(strPages);

Book book=new Book(isbn,strAuthor,pages,strDescription);

bs.storeBook(book);

request.setAttribute("book",book);

return;

}
catch(Exception ex)
{
out.println(ex.toString());
}
finally {
out.close();
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}
---------------------------------------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package servlet.view;

import servlet.model.Book;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
*
* @author NIIT
*/
public class SuccessServlet extends HttpServlet {

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Book book=(Book) request.getAttribute("book");
try {
// out.println("<a href='index.jsp'>Home Page</a>");
// out.println("<h1>Success</h1>");
// out.println("<p>");
// out.println("Your request to add the Book title");
// out.println("<font color=green>");
// out.println("<u>");
// out.print("<i>" + book.getDescription()+ "</i>");
// out.println("</u>");
// out.println("</font>");
// out.println("By");
// out.println("<font color=green>");
// out.println("<u>");
// out.print("<i>" + book.getAuthor()+ "</i>");
// out.println("</u>");
// out.println("</font>");
// out.println(" was successful.");
// out.println("</p>");
} finally {
out.close();
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}
---------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">


<struts-config>
<form-beans>

</form-beans>

<global-exceptions>

</global-exceptions>

<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>

<action-mappings>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
<action path="/com.struts.controller" type="com.struts.controller.DeleteBookStruts">
<forward name="SuccessDelete" path="servlet.view"/>
<forward name="ErrorServlet" path="servlet.view"/>
</action>
<action path="/com.struts.controller" type="com.struts.controller.AddBookStruts">
<forward name="Success" path="/success.jsp"/>
<forward name="Error" path="/Error.jsp"/>
</action>

</action-mappings>


<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

<message-resources parameter="com/myapp/struts/ApplicationResource"/>

<!-- ========================= Tiles plugin ===============================-->
<!--
This plugin initialize Tiles definition factory. This later can takes some
parameters explained here after. The plugin first read parameters from
web.xml, thenoverload them with parameters defined here. All parameters
are optional.
The plugin should be declared in each struts-config file.
- definitions-config: (optional)
Specify configuration file names. There can be several comma
separated file names (default: ?? )
- moduleAware: (optional - struts1.1)
Specify if the Tiles definition factory is module aware. If true
(default), there will be one factory for each Struts module.
If false, there will be one common factory for all module. In this
later case, it is still needed to declare one plugin per module.
The factory will be initialized with parameters found in the first
initialized plugin (generally the one associated with the default
module).
true : One factory per module. (default)
false : one single shared factory for all modules
- definitions-parser-validate: (optional)
Specify if xml parser should validate the Tiles configuration file.
true : validate. DTD should be specified in file header (default)
false : no validation

Paths found in Tiles definitions are relative to the main context.
-->
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>

<!-- ========================= Validator plugin ================================= -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>
---------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>AddBookServlet</servlet-name>
<servlet-class>servlet.view.AddBookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddBookServlet</servlet-name>
<url-pattern>/add.view</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
---------------------------------------------------------------------------
<%--
Document : success
Created on : May 25, 2010, 11:56:30 AM
Author : NIIT
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Success Page</title>
</head>
<body>
<h1>Success!</h1>
<p>
Your request to add the Book title was successful.
</p>
</body>
</html>
---------------------------------------------------------------------------
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<html:html lang="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message key="welcome.title"/></title>
<html:base/>
</head>
<body style="background-color: white">

<logic:notPresent name="org.apache.struts.action.MESSAGE" scope="application">
<div style="color: red">

</div>
</logic:notPresent>

<h3><bean:message key="welcome.heading"/></h3>
<p><bean:message key="welcome.message"/></p>
<a href="addbooks.jsp">Add Book</a>

</body>
</html:html>
---------------------------------------------------------------------------
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<jsp:forward page="Welcome.do"/>
View Answers









Related Pages:
Unable to understand Struts - Struts
Unable to understand Struts  I am studying in GNIIT from NIIT. Here in 4th sem we have stuts also but I am not able to understand it. I've made... = "success"; /** * This is the action called from the Struts
Form unable to hold values - Struts
Form unable to hold values  I have a form with a combo box having hasmap property. When i submit the search button and in event of an error, it does not bring the value only for this drop down box? Any ideas
unable to execute the examples
unable to execute the examples  unable to execute the examples given for struts,ejb,or spring tutorials.Please help I am a beginner
Struts2...problem in JSP..unable to get the values for menuTitle!!!
Struts2...problem in JSP..unable to get the values for menuTitle!!!  ..." encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd
struts - Struts
of struts, u understand wverything goto google type for strut-blank.jar...struts  hi, what is meant by struts-config.xml and wht are the tags... 2. wht is the difference b/w the web.xml and struts-config.xml 3. what
Struts - Struts
Struts  Dear Sir , I am very new in Struts and want to learn about validation and custom validation. U have given in a such nice way to understand but little bit confusion,Plz could u provide the zip for address
Struts Video Tutorials
on Struts framework. These video tutorials is easy to learn and understand. You...Struts Video Tutorials - Now you can learn the Struts programming easily and in less time. Struts Video tutorials are very extensive and explained
What is Struts?
What is a Struts? Understand the Struts framework This article tells you "What is a Struts?". Tells you how Struts learning is useful in creating... are now preferring Struts based applications. Struts is good as it provides
doubt in struts - Struts
doubt in struts   i don't understand the concept on Resource bundle in struts can u please help me out
Struts 2.1.8 - Struts 2.1.8 Tutorial
Struts 2.1.8 - Struts 2.1.8 Tutorial       The Struts 2.1.8 is latest release of Struts 2 as on 28-April-2010.  In this tutorial we will understand the features of Struts 2.1.8
Java - Struts
Java  Thank you so much , Tell me how to use "ejb in struts" for database acessing, i am not able to get the look up in struts by using ejb, how to get , i have got the error like this unable to bound,and page not found 
unable to open the service tomcat5
unable to open the service tomcat5  While trying to run tomcat server getting "unable to open the service tomcat5" error after installed tomcat
Struts Tag Lib - Struts
Struts Tag Lib  Hi i am a beginner to struts. i dont have to understand the TagLib uri. Any body could you please give me some brief steps reg.... JSP Syntax Examples in Struts : Description The taglib
Struts for Java
Struts for Java  What do you understand by Struts for Java? Where Struts for Java is used? Thanks   Hi, Struts for Java is programming framework. The Struts for Java is software development framework for creating
JSP - Struts
JSP  am using struts frame work for my project, my requirement is 1.in jsp page Class(drop down list) will take all classes in school from database... to display a text box with his grade.....which am unable to do... please help
JSP - Struts
JSP  am using struts frame work for my project, my requirement is 1.in jsp page Class(drop down list) will take all classes in school from database... to display a text box with his grade.....which am unable to do... please help
JSP - Struts
JSP  am using struts frame work for my project, my requirement is 1.in jsp page Class(drop down list) will take all classes in school from database... to display a text box with his grade.....which am unable to do... please help
Understanding Struts - Struts
Understanding Struts  Hello, Please I need your help on how I can understand Strut completely. I am working on a complex application which... books on how to understand this, but still not getting it. So , I just need
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... i was using this code.... try { Driver d=(Driver)Class.forName
Unable to execute JSP page
Unable to execute JSP page  I have written one jsp file. It contains html tags and jsp directives. I have saved the file with the extension .jsp. The tomcat server is already running onto my machine. I have saved the jsp file
Unable to use JMXMP with Knopflerfish?
Unable to use JMXMP with Knopflerfish?  I have a bundle which runs properly with Eclipse, then I generate the jar file and try to use it with Knopflerfish, then I get the following exception java.net.MalformedURLException
struts with hibernate
struts with hibernate   /SearchTutorial.jsp(4,2) Unable to find setter method for attribute: locale <%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-html" prefix="html" %> <
Please help me understand this query
Please help me understand this query  Hi, Could someone please help me understand the following query. Im finding difficulty relating it :-( Pls Help! select * from cbpartner where CBPartner.IsSummary='N' and salesrep_id
Unable to compile Servlet
Unable to compile Servlet  First I installed the tomcat server in C:\apache-tomcat-6.0.14 directory. Then I created a system variable CATALINA_HOME with the value C:\apache-tomcat-6.0.14. Then I created another system variable
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... i was using this code. try { Driver d=(Driver)Class.forName
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to run servlet
unable to run servlet  Dear sir/madam i have jdk1.5.0_04 and tomcat server 1.0.16 installed on my computer. on my computer servlet is compiling properly on command prompt but during servlet execution on browser with following url
Struts - Framework
Struts  Hi, I am doing a reverse engineering in a project based on struts 1.1,after seeing the log file, i encounter some lines that are written... of '19' over here So i am not able to understand exactly what is happening
unable to import class com.opensymphony.xwork2.ActionContext not found
unable to import class com.opensymphony.xwork2.ActionContext not found  Imported class com.opensymphony.xwork2.ActionContext not found gettin the above error
Unable to compile class for JSP - WebSevices
Unable to compile class for JSP  org.apache.jasper.JasperException: Unable to compile class for JSP When I am trying to access a java file kept under src folder under a package from a jsp page placed under web directory, I am
struts validation
struts validation  I want to apply validation on my program.But i am... unable to solve the problem. please kindly help me.. I describe my program below...;%@ include file="../common/header.jsp"%> <%@ taglib uri="/WEB-INF/struts
struts validation
struts validation  I want to apply validation on my program.But i am... unable to solve the problem. please kindly help me.. I describe my program below...;%@ include file="../common/header.jsp"%> <%@ taglib uri="/WEB-INF/struts
unable to connect to server - JSP-Servlet
unable to connect to server  thank you for the program code for inserting and reteriving the image but i am unable to deploy these two programs in weblogic/apache servers can any one help me how to do this ?   Hi Friend
What do you understand by private, protected and public?
What do you understand by private, protected and public?   Hi, What do you understand by private, protected and public? thanks
Struts2 Helloworld problem -Please help - Struts
Struts2 Helloworld problem -Please help  Hi I am a beginner in Struts2. I tried some HelloWorld example in Struts2, to understand. But due to some problem I unable to execute the program successfully. Please find my example
Unable to install Subversion plugins in MyEclipse
Unable to install Subversion plugins in MyEclipse  Thanks for your reply Deepak. I am using MyEclipse Blue Edition 8.6 M1. I tried adding Subversion plugins and got error. This is the path i followed: Help --> MyEclipse
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data..
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data..  I have a class file AbstractDataAccessObject with the below code.... If I use it also, unable to connect to backend oracle database. Let me
Validation - Struts
Validation  How can i use validation framework i don't understand am having problem while implementing this, can anybody help me with example.  Hi friend, Phone validation using javaScript function
Unable to create annotations in hibernate 4.0
Unable to create annotations in hibernate 4.0  I worked on a similar example as yours.But when I create a new hibernate console configuration for this new project,I get this error,the console configuration gets created I but when
Struts Guide
with let's understand the Jakarta Struts Framework. - What is Struts... Struts Guide       - This tutorial is extensive guide to the Struts Framework
unable to see the output of applet. - Applet
unable to see the output of applet.  Sir, I was going through the following tutorial http://www.roseindia.net/java/example/java/applet/FirstApplet.shtml of your website. this page has got the "link" which says Try online
What is Struts Framework?
What is Struts Framework? Learn about Struts Framework This article is discussing the Struts Framework. It is discussing the main points of Struts framework. If you are trying understand Struts and searching for "What is Struts
Struts 2 tutorial for beginners with examples
and understand the core concepts of Struts. View Struts 2 tutorial...Struts 2 tutorial for beginners with examples  Where is the Struts 2 tutorial for beginners with examples on your website. Thanks   Hi
Struts Projects
In this section we will understand how Spring Hibernate and Struts... Struts Projects Easy Struts Projects to learn and get into development ASAP. These Struts Project will help you jump the hurdle of learning complex
"unable to load tag handler struts.views.jsp.ui.Form tag "
"unable to load tag handler struts.views.jsp.ui.Form tag "   while working with tags i show"unable to load tag handler struts.views.jsp.ui.Form tag " same error is also with iterator tag

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.