Thursday, January 3, 2013

Select an element from xml file using where clause

Here is the sample xml file
<?xml version="1.0" encoding="utf-8" ?>
<urls>
<url keyword="RA">http://google.com </url>
<url keyword="NC">http://google.com </url>
</urls>

Here is the sample code
XDocument doc=XDocument.Load(Server.MapPath("~/urllist.xml"));
var url = (from ur in doc.Descendants("url")
where ur.Attribute("keyword").Value=="RA"
select ur.Value).ToList();

Thursday, December 27, 2012

Upload file using JSP

I found a good article to upload a file using jsp here . I just modified it little so that it can upload file to the root directory of the webapp.

fileindex.jsp

<%@ page language="java" %>
<HTml>
<HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>
<% // for uploading the file we used Encrypt type of multipart/form-data and input of file type to browse and submit the file %>
<BODY> <FORM ENCTYPE="multipart/form-data" ACTION="single_upload_page.jsp" METHOD=POST>
<br><br><br>
<center><table border="2" >
<tr><center><td colspan="2"><p align="center"><B>PROGRAM FOR UPLOADING THE FILE</B><center></td></tr>
<tr><td><b>Choose the file To Upload:</b></td>
<td><INPUT NAME="F1" TYPE="file"></td></tr>
<tr><td colspan="2"><p align="right"><INPUT TYPE="submit" VALUE="Send File" ></p></td></tr>
<table>
</center>
</FORM>
</BODY>
</HTML>

Tuesday, December 25, 2012

jsp with beans example

Here is an example :

index.jsp
---------------------

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="us" scope="request" class="msgbean.User"></jsp:useBean>
<%
if (request.getParameter("Name") != null) {
//out.write(request.getParameter("Name"));
us.setName(request.getParameter("Name"));
us.setEmail(request.getParameter("Email"));
}
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form method="post">
<table>
<tr><td>Name:</td><td><input type="text" name="Name"/></td></tr>
<tr><td>Email:</td><td><input type="text" name="Email"/></td></tr>
<tr><td><input type="submit" value="Submit"/></td></tr>
</table>
</form>

You entered:<br />

Name: <%= us.getName()%></br>
Email: <%= us.getEmail()%></br>
</body>
</html>
----------------------------------

Sunday, November 25, 2012

Get number of element of specific name in a xml file

XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("~/pp1.xml"));
string PersonCount = xdoc.DocumentElement.SelectNodes("//persons/person").Count.ToString();
Response.Write(PersonCount);

Tuesday, October 16, 2012

ওয়ালটন প্রিমো (অ্যান্ড্রয়েড) রিভিউ

আমি নিজে অনেকদিন থেকেই সনি এরিকসন এক্সপেরিয়া এক্স এইট চালাই। এক বন্ধুর জন্য গত শনিবার গেলাম এন্ড্রয়েড ফোন কিনতে। প্রথমে ভেবেছিলাম যে সিম্ফোনি w5 নিবো কিন্তু পরে নেট ঘেটে দেখলাম যে দাম এবং কনফিগারেশনের দিক থেকে ওয়ালটন প্রিমো এগিয়ে। কিনলাম ওয়ালটন এর বিজয় সরনী এর শো রুম থেকে। কেনার পর একদিন ব্যবহার করার সুযোগ পেলাম। তাতে যা দেখলাম টাকার হিসেবে অসাধারন জিনিস (আমার মতে)।

Monday, September 24, 2012

Make your windows 7 laptop into wifi hotspot

Make sure you have installed Microsoft Virtual Wifi miniport adapter

 

Then make command as follows:
C:\Windows\system32>netsh wlan set hostednetwork mode=allow ssid=MyWifi key=password keyUsage=persistent

To start your network
C:\Windows\system32>netsh wlan start hostednetwork

To Stop your network
C:\>netsh wlan show hostednetwork

Share your internet connection by going to network sharing center





Monday, June 11, 2012

Create a colorful flashlight in android

Create an android project in eclipse and pasted the following code in the main activity class:

package com.rayhan.nothing;

import java.util.Random;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class AndruTestActivity extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

View v=findViewById(R.id.mainlayout);

v.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Random rnd=new Random();

v.setBackgroundColor(rnd.nextInt());

}
});

}
}

//------------------------------------------------

And here is the xml file for the layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:background="@color/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

</LinearLayout>

What is DaemonSet in Kubernetes

 A DaemonSet is a type of controller object that ensures that a specific pod runs on each node in the cluster. DaemonSets are useful for dep...