For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Friday, October 25, 2013

ALTERNATE OF OR ANY OTHER LOGIC TAG IN STRUTS

ALTERNATE OF <logic:equal> OR ANY OTHER LOGIC TAG IN STRUTS
----------------------------------------------------------------------------------------
We need to write very much <logic:equal name> if there are lot of if conditions in you page...so how we use native if condition in struts. I have faced the same problem and find the solution. the solution is in listed below code.


=======================================================
Using  <logic:equal name> 

<logic:notEmpty name="myProductList" scope="request">
<table>
<logic:iterate id="prodIterateId" name="myProductList">
<tr>
    <logic:equal name="prodIterateId" property="catId" value="1">
        <td  align="center"><html:text name="prodIterateId" property="catId" value="DESKTOP COMPUTER"/></td>
    </logic:equal>
    <logic:equal name="prodIterateId" property="catId" value="2">
        <td align="center"><html:text name="prodIterateId" property="catId" value="LAPTOP"/></td>
    </logic:equal>
    <logic:equal name="prodIterateId" property="catId" value="3">
        <td  align="center"><html:text name="prodIterateId" property="catId" value="PAMTOP"/></td>
    </logic:equal>
     <logic:equal name="prodIterateId" property="catId" value="4">
        <td  align="center"><html:text name="prodIterateId" property="catId" value="PAD"/></td>
    </logic:equal>
        <td  align="center"><html:text name="prodIterateId" property="productName" readonly="true" size="33"/></td>
        <td  align="center"><html:text name="prodIterateId" property="productPrice" readonly="true" size="33"/></td>
        <td  align="center"><html:text name="prodIterateId" property="productCode" readonly="true" size="33"/></td>
    </tr>
    </logic:iterate>
    </table>
</logic:notEmpty>
============================================================

Using native IF condition

<logic:notEmpty name="myProductList" scope="request">
<table>
    <logic:iterate id="prodIterateId" name="myProductList">
        <tr>
            <bean:define id="catId_Value" name="prodIterateId" property="catId"  type="java.lang.Integer" />
            <%
                int c_id=catId_Value.intValue();
                String cat_Name="";
                if(c_id==1) {cat_Name="DESKTOP COMPUTER";}
                if(c_id==2) {cat_Name="LAPTOP"; }
                if(c_id==3) {cat_Name="PAMTOP"; }
                if(c_id==4) {cat_Name="PAD"; }
            %>
        <td  align="center"><html:text name="prodIterateId" property="catId" value="<%=cat_Name%>"/></td>
        <td  align="center"><html:text name="prodIterateId" property="productName" readonly="true" size="33"/></td>
        <td  align="center"><html:text name="prodIterateId" property="productPrice" readonly="true" size="33"/></td>
        <td  align="center"><html:text name="prodIterateId" property="productCode" readonly="true" size="33"/></td>
    </tr>
    </logic:iterate>
    </table>
</logic:notEmpty>


Share:

Ajax in struts

How to use ajax in struts and hibernate.

Ajax is very important in website coding.
Here I am demonstrating how to use jquery ajax in struts and hibernate.


struts-config.xml
--------------------------
<action input="/" path="/amittest" scope="request" type="com.test.actions.AmitTestAction" parameter="method">
<forward name="success" path="/Webs/Input/amittest.jsp"/>
</action>
====================================================


query.hbm.xml
-----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <sql-query cache-mode="ignore" cacheable="false" flush-mode="always" name="chkBook"> SELECT COUNT(*) FROM book_master WHERE code_id=:code AND serial_id>=:serial </sql-query>
</hibernate-mapping>
====================================================

MyUtilDao.java
------------------------------
package dao;
import org.hibernate.CacheMode;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import plugins.HibernateSessionFactory;
public class MyUtilDao {
    public int chkBook(int code,int serial){
        Session ssn = null;
        ssn = HibernateSessionFactory.getSession();
        ssn.setCacheMode(CacheMode.GET);
        Query qry = ssn.getNamedQuery("chkBook");
        qry.setParameter("code", code);
        qry.setParameter("serial", serial);
        Object tot = qry.uniqueResult();
        int total = 0;
        if (tot != null) {
            total = Integer.parseInt(tot.toString());
        } else {
            total = 0;
        }
        return total;
    }
 
}
====================================================

AmitTestAction.java
-------------------------
package mytest.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import dao.MyUtilDao;
import plugins.HibernateSessionFactory;

public class AmitTestAction  extends org.apache.struts.actions.DispatchAction {
     private final static String SUCCESS = "success";
     public ActionForward showForm(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
       
         MyUtilDao myUtiDaoObj=new MyUtilDao();
       
         String ffor= request.getParameter("ffor");
         if(ffor.compareTo("chkBook")==0) {
            int code= Integer.parseInt(request.getParameter("code"));
            int erial= Integer.parseInt(request.getParameter("serial"));
            int total=myUtiDaoObj.chkBook(code,serial);
            request.setAttribute("total", total);
            request.setAttribute("ffor", "chkBook");
         }
         return mapping.findForward(SUCCESS);
      }
}
====================================================
amittest.jsp
<%
if(request.getAttribute("ffor")!=null) {
    if(request.getAttribute("ffor").toString().compareTo("chkBook")==0) {
        out.print(request.getAttribute("total"));
    }
}
%>
====================================================
BookAdd.jsp

<input type="button" name="btn1" value="Button" onclick="dotest();"/>
<html:button property="button" value="Save" onclick="do_save()"/>
<script>

 var code=222;
var serial=111;
function do_save() {
        var ajaxans="";
        $.ajax({
                    url: "amittest.do?method=showForm",
                    type: "POST",
                    async: false,
                    cache: false,
                    data:   { 'ffor':'chkBook',
                              'code':code,
                              'serial':serial},
                    success: function(html) {
                             ajaxans=html;
                            }
                }
             );
       if(ajaxans=="1" || parseInt(ajaxans)==1) {
           alert("This is already exists");
           return;
       }    
        var r=confirm("Do you want to save?");
        if (r==true) {
            document.forms[0].action="BookMasterAdd.do?method=processForm";
            document.forms[0].submit();
        }
    }

   function dotest() {
       /*$.post("http://localhost:8080/mytest/amittest.do?method=showForm",{'method':'showForm'},function(ans) {
alert(ans);
});*/
      /*// done
       *$.post("amittest.do?method=showForm",{'method':'showForm'},function(ans) {
alert(ans);
});*/
      /* done
       * $.post("amittest.do?method=showForm",function(ans) {
alert(ans);
});*/
      /* $.get("amittest.do?method=showForm",function(ans) {
alert(ans);
});*/
     
      /* $.get("amittest.do?method=showForm",{'val1':'Hi'},function(ans) {
alert(ans);
});*/  
   
      /*   $.post("amittest.do?method=showForm",{'val1':'Hi'},function(ans) {
alert(ans);
});*/
    /*  $.post("amittest.do?method=showForm",{'ffor':'chkExistReceiptBookMaster',
                                            'zone_code':'8004500',
                                            'frm_serial':'11'
                                           },function(ans) {
alert(ans);
});*/
}
</script>
====================================================



Share:

Saturday, October 19, 2013

java.lang.OutOfMemoryError: PermGen space in netbeans

java.lang.OutOfMemoryError: PermGen space in netbeans

How to solve it in netbeans:
1- Right click on server
2- properties
3- select platform
4-in VM option paste as : -Xmx512m -Xms512m -XX:MaxPermSize=512m

java.lang.OutOfMemoryError: PermGen space in netbeans

Share:

Thursday, October 10, 2013

DispatchMapping does not define a handler property




You may face this error while working on java struts:

"DispatchMapping[/login] does not define a handler property"




Answer of this issue is "parameter attribute mention in struts-config for method of Action class"
Share:

Cannot retrieve definition for form bean on action

javax.servlet.jsp.JspException: Cannot retrieve definition for form bean stdname on action regist 

Ans:spelling mistake in tags, so check it and correct it in struts-config.xml file
Share:

Action missing resource in key method map

Action missing resource in key method map

Ans:It means the you have put some spaces in .properties file or missing some property key and its value
Share:

Cannot find ActionMappings or ActionFormBeans collection

org.apache.jasper.JasperException: javax.servlet.
ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
root cause
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
root cause
javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection


Ans: One of the most common error is that .. that you have missed struts-config file path in web.xml file.

for Ex: <param-value>/WEB_INF/struts-config.xml</param-value>
so change it as <param-value>/WEB-INF/struts-

config.xml</param-value>
Share:

message No action instance for path / could be created error in struts

message No action instance for path /getcity could be created in struts
description The server encountered an internal error (No action instance for path /getcity could be created) that prevented it from fulfilling this request.

Ans: it means that you miss-spelled class information just see [type="con.test.action.DoLogin"] it must be 
type="com.test.action.DoLogin"

<action name="logform" path="/getcity"  type="con.test.action.DoLogin" scope="request" parameter="action">
            <forward name="cityyyy" path="/city_confirm.jsp"/>
        </action>
Share:

Action does not contain specified method (check logs)

javax.servlet.ServletException: java.lang.
NoSuchMethodException: Action[/salary] does not contain specified method (check logs)
java.lang.NoSuchMethodException: Action[/salary] does not contain specified method (check logs)

Ans: This means "salary" method must be a text in the .jsp file:
public ActionForward salary(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws Exception {
        LoginForm lfm=(LoginForm)form;
        request.setAttribute("empName", lfm.getAname());
        return mapping.findForward("salary");
    }

<html:form action="/salary" method="post">
Salary: <html:text property="salary"/><br/>
Emp code <html:text property="empcode"/><br/>
<html:submit value="salary" property="action"/>
</html:form>struts-config.xml
 
Share:

Cannot find message resources under key org.apache.struts.action.MESSAGE

Cannot find message resources under key org.apache.struts.action.MESSAGE

 javax.servlet.jsp.JspException: Cannot find message resources under key org.apache.struts.action.
MESSAGE
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find message resources under key org.apache.struts.action.MESSAGE

 
Ans:
1- create a package: com.test.properties
2- under that package create a "Common.properties" file with this contents or just empty it:

#common module error message
error.common.name.required = Name is required.

#common module label message
label.common.name = UserName
label.common.button.submit = Submit
label.common.button.reset = Reset


3- just add the message-resource tag in struts-config.xml file as listed below:
<message-resources parameter="com.test.properties.Common"></message-

resources> 
Share:

Cannot cast from ActionForm to form error in struts

I was working in struts and faced "Cannot cast from ActionForm to StudentForm" error.

to solve follow the steps:

Ans: It means you have not import
"import org.apache.struts.action.ActionForm;" int Form class
and can not extends "ActionForm" in that class
for ex:

import org.apache.struts.action.
ActionForm;
public class StudentForm  extends ActionForm {
Share:

Turn off the new tab page in firefox


Turn off the new tab page in firefox



type about:config in url text box and Enter.
click ok
Type browser.newtab.url in the search box.
Double-click the browser.newtab.url preference and change the url from about:newtab toabout:blank.
Click OK and close the about:config tab.
Share:

openssl_encrypt openssl_decrypt in php

openssl_encrypt openssl_decrypt in php

$method = 'aes-128-ecb';
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
$msg="Hi this is the testing for encoding and decoding";

$en=openssl_encrypt($msg, $method, 'def', true, $iv);
echo $en;

$de=openssl_decrypt($en, $method, 'def', true, $iv);
echo $de;

Share:

Array to object in php

Array to object in PHP

$obj = (object) array('nName' => 'my_name', 'address' => 'my_address');
echo $obj->nName;
echo $obj->address;
Share:

JSON in PHP Simple

Simple JSON in PHP

test.php
<script type="application/javascript">
function getip(json){
    alert(json);
}
</script>
<script type="application/javascript" src="http://localhost:90/test/a1.php?callback=getip"></script>


a1.php
<?php
header('content-type: application/json; charset=utf-8');

$data = json_encode($_SERVER['REMOTE_ADDR']);
echo $_GET['callback'] . '(' . $data . ');';
?>
Share:

Show DOCX meta data in php

Show DOCX meta data in php

 

 <?php
/*<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <dc:title>Title Proforma-For-Application</dc:title>
  <dc:subject>Subject Proforma-For-Application.docx<

/dc:subject>
  <dc:creator>MICROSOFT2012</dc:creator>
  <cp:keywords>Keywords Proforma-For-Application.docx</cp:keywords>
  <dc:description>This is comments Proforma-For-Application.docx</dc:description>
  <cp:lastModifiedBy>MICROSOFT2012</cp:lastModifiedBy>
  <cp:revision>11</cp:revision>
  <dcterms:created xsi:type="dcterms:W3CDTF">2013-07-17T11:50:00Z</dcterms:created>
  <dcterms:modified xsi:type="dcterms:W3CDTF">2013-07-17T12:06:00Z</dcterms:modified>
  <cp:category>Category Proforma-For-Application.docx</cp:category>
</cp:coreProperties>
*/
class Docx{
    var $xml_data = "";
    function openDocx($path_of_file) {
        $zip = new ZipArchive;
        $ans = $zip->open($path_of_file);
        if ($ans === TRUE) {
            $folder = uniqid("", true);
            mkdir($folder, 0700);
            $zip->extractTo($folder, array("docProps/core.xml"));
            $zip->close();
            $this->xml_data = file_get_contents($folder."/docProps/core.xml");    
            unlink($folder."/docProps/core.xml");
            rmdir($folder."/docProps");
            rmdir($folder);
        }                
    }
        
    function showTitle(){
        $title_start = explode("</dc:title>", $this->xml_data);    
        //$meta_title_end = explode("<dc:title>", $meta_title_start[0]);
        //return $meta_title_end[1];    
        return (explode("<dc:title>", $title_start[0])[1]);    
    }
        
    function showSubject(){
        $subject_start = explode("</dc:subject>", $this->xml_data);    
        return (explode("<dc:subject>", $subject_start[0])[1]);    
    }
        
    function showCreator(){
        /*$creator_start = explode("</dc:creator>", $this->xml_data);    
        $creator_end = explode("<dc:creator>", $creator_start[0]);    
        return $creator_end[1];*/    
        //$creator_end = explode("<dc:creator>", (explode("</dc:creator>", $this->xml_data))[0]);    
        return (explode("<dc:creator>", explode("</dc:creator>", $this->xml_data)[0])[1]);
    }
        
    function showKeywords(){
        $keywords_start = explode("</cp:keywords>", $this->xml_data);    
        $keywords_end = explode("<cp:keywords>", $keywords_start[0]);    
        return $keywords_end[1];
    }
        
    function showDescription(){
        $description_start = explode("</dc:description>", $this->xml_data);    
        $description_end = explode("<dc:description>", $description_start[0]);    
        return $description_end[1];
    }
        
    function showLastModifiedBy(){
        $lastmodifiedby_start = explode("</cp:lastModifiedBy>", $this->xml_data);    
        $lastmodifiedby_end = explode("<cp:lastModifiedBy>", $lastmodifiedby_start[0]);    
        return $lastmodifiedby_end[1];
    }
        
    function showRevision(){
        $revision_start = explode("</cp:revision>", $this->xml_data);    
        $revision_end = explode("<cp:revision>", $revision_start[0]);    
        return $revision_end[1];
    }
        
    function showDateCreated(){
        $datecreated_start = explode("</dcterms:created>", $this->xml_data);    
        $datecreated_end = explode("<dcterms:created xsi:type=\"dcterms:W3CDTF\">", $datecreated_start[0]);    
        return $datecreated_end[1];
    }
        
    function showDateModified(){
        $datemodified_start = explode("</dcterms:modified>", $this->xml_data);    
        $datemodified_end = explode("<dcterms:modified xsi:type=\"dcterms:W3CDTF\">", $datemodified_start[0]);    
        return $datemodified_end[1];
    }
        
    function showCategory(){
        $category_start = explode("</cp:category>", $this->xml_data);    
        $category_end = explode("<cp:category>", $category_start[0]);    
        return $category_end[1];
    }
}
$docx = new Docx();
$docx_file_name_with_path = "Proforma-For-Application.docx";
$docx->openDocx($docx_file_name_with_path);
echo "<strong>File : ",$docx_file_name_with_path . "</strong><br>";
echo "Title : " , $docx->showTitle() . "<br>";
echo "Subject : " , $docx->showSubject() . "<br>";
echo "Author : " , $docx->showCreator() . "<br>";
echo "Category : " , $docx->showCategory() . "<br>";
echo "Keywords : " , $docx->showKeywords() . "<br>";
echo "Comments : " , $docx->showDescription() . "<br>";
echo "Last Modified By : " , $docx->showLastModifiedBy() . "<br>";
echo "Revision : " , $docx->showRevision() . "<br>";
echo "Created on: " , $docx->showDateCreated() . "<br>";
echo "Modified on: " , $docx->showDateModified() . "<br>";
?>

 

Share:

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive