For smart Primates & ROBOTS (oh and ALIENS ).

Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

Saturday, November 02, 2013

Show records without class in hibernate and struts

Show all records without pojo class in hibernate and struts

Struts and Hibernate if you need to show all records from database table then you need to create a pojo class...in some cases you not need to use pojo class then how can you achieve to show all records? I have faced the same problem and overcome it with listed below code.


In query.hbm.xml file
<sql-query name="TestTestTest">
select user_name, user_id, password, cd, user_status,CAST(from_dt AS CHAR) as from_date from user_info
</sql-query>

In your action class

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
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 org.hibernate.*;
import plugins.HibernateSessionFactory;

Session ssn = null;
ssn = HibernateSessionFactory.getSession();
ssn.setCacheMode(CacheMode.GET);
Query qry = ssn.getNamedQuery("TestTestTest");
List <Object[]>containerResults = qry.list();
for(java.lang.Object[] result : containerResults) {
    System.out.print("\n"+result[0]+"======"+result[1]+"======"+result[2]+"======"+result[3]+"======"+result[4]+"======"+result[5]);
}
Share:

Thursday, October 10, 2013

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:

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:

Saturday, October 05, 2013

Remove Controller and it's method form codeigniter

How to remove Controller in  codeigniter and it's method just show it's parameter in url for ex:


http://localhost:90/CodeIgniter_2.1.4_new/category/show/this-is-the-test.html
as
http://localhost:90/CodeIgniter_2.1.4_new/this-is-the-test.html

Goto routes.php under config directory:
write this listed below line
$route['(:any)'] = "category/show/$1";
==============================
====================================================
create a new file "category.php"
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Category extends CI_Controller {
    public function index() {
        $this->load->view('welcome_message');
    }
    public function show($text) {
            echo "aaaaa".$text;  
    }
}
Share:

Send email in Codeigniter

Send email in Codeigniter


$this->load->library('email');
$this->email->from('my@my-site.com', 'My Name');
$this->email->subject('Test subject');
$this->email->message('Testing email.');
$this->email->attach('/path/img1.jpg');
$this->email->send();

Share:

Use value in index method in Codeigniter

Use value in index method in Codeigniter

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends CI_Controller {
    public function index($param)
    {
        echo $param;
        $this->load->view('category_
message');
    }
    public function _remap($param) {
        $this->index($param);
    }
}

use is as:
http://localhost:90/CodeIgniter_2.1.4/category/laptop
Share:

Ads Inside Post

Powered by Blogger.

Archive