<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.: Mr.cAm - Y: cuong_pho_nui :. &#187; java</title>
	<atom:link href="http://phamcuong.info/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://phamcuong.info</link>
	<description>Khám phá thế giới (^o^)</description>
	<lastBuildDate>Tue, 27 Jul 2010 03:02:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Cài phần mềm cho máy Samsung</title>
		<link>http://phamcuong.info/2010/04/05/cai-ph%e1%ba%a7n-m%e1%bb%81m-cho-may-samsung/</link>
		<comments>http://phamcuong.info/2010/04/05/cai-ph%e1%ba%a7n-m%e1%bb%81m-cho-may-samsung/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 16:09:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bất chợt]]></category>
		<category><![CDATA[cài game]]></category>
		<category><![CDATA[cài jad]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[samsung]]></category>
		<category><![CDATA[tạo file jad]]></category>

		<guid isPermaLink="false">http://phamcuong.info/?p=895</guid>
		<description><![CDATA[Máy samsung cài toàn lạ người, chắc để cho mấy ông ở tiệm ăn thêm :-s TRƯỚC TIÊN BẠN COPY FILE JAR VÀ FILE JAD ( nếu phần mềm kô có file jad thì dùng phần mềm tạo file jad ở đây http://www.mediafire.com/download.php?oztnylyzjmm , down về chạy phần mềm, kéo thả file jar nó sẽ [...]]]></description>
			<content:encoded><![CDATA[<p>Máy samsung cài toàn lạ người, chắc để cho mấy ông ở tiệm ăn thêm :-s<span id="more-895"></span><br />
TRƯỚC TIÊN BẠN COPY FILE JAR VÀ FILE JAD ( nếu phần mềm kô có file jad thì dùng phần mềm tạo file jad ở đây http://www.mediafire.com/download.php?oztnylyzjmm , down về chạy phần mềm, kéo thả file jar nó sẽ sinh ra file jad cùng thư mục với jar) VÀO MUC OTHER CỦA THẺ NHỚ RỒI CHUYỂN TẤT CẢ VÀO TRONG PHONE<br />
SAU ĐÓ BẠN BẤM MÃ *#9998*4678255# SAU ĐÓ BẠN VÀO PHONE >QUẢN LÝ FILE>FILE KHÁC.BẠN TÌM FILE ĐUÔI JAD ĐỂ INTALL(LƯU Ý INTALL = NÚT BẾN TAY TRÁI PHÍM MENU NHA.</p>
<p>Một số mã lệnh để mở máy loại khác:<br />
Samsung J600,U600: *#9998*4678255#<br />
Samsung D500: #*5737425#<br />
Samsung D900: #*5737425#<br />
Samsung E250:*#52828378#<br />
Samsung Z720: #*5737425#<br />
Samsung u900 soul: *#0002*28346#<br />
samsung E900 :*#9998*5282#<br />
samsung D900,X820 : *#9998*52824678255#<br />
samsung D600 : #*5737425#</p>
]]></content:encoded>
			<wfw:commentRss>http://phamcuong.info/2010/04/05/cai-ph%e1%ba%a7n-m%e1%bb%81m-cho-may-samsung/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lỗi connect database, xa xưa nhưng gây lỗi 500</title>
		<link>http://phamcuong.info/2009/12/10/l%e1%bb%97i-connect-database-xa-x%c6%b0a-nh%c6%b0ng-gay-l%e1%bb%97i-500/</link>
		<comments>http://phamcuong.info/2009/12/10/l%e1%bb%97i-connect-database-xa-x%c6%b0a-nh%c6%b0ng-gay-l%e1%bb%97i-500/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 16:59:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Lập trình]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[lỗi 500]]></category>

		<guid isPermaLink="false">http://phamcuong.info/?p=597</guid>
		<description><![CDATA[Tối đẹp trời này tớ đã bị mắc lỗi này và mất cả tiếng đồng hồ ngồi gãi đầu, mãi mới nhớ ra. HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception java.lang.NullPointerException Đây là dòng báo lỗi của em [...]]]></description>
			<content:encoded><![CDATA[<p>Tối đẹp trời này tớ đã bị mắc lỗi này và mất cả tiếng đồng hồ ngồi gãi đầu, mãi mới nhớ ra.</p>
<p><span id="more-597"></span></p>
<h1>HTTP Status 500 -</h1>
<hr size="1" noshade="noshade" /><strong>type</strong> Exception report</p>
<p><strong>message</strong></p>
<p><strong>description</strong> <span style="text-decoration: underline;">The server encountered an internal error () that  prevented it from fulfilling this request.</span></p>
<p><strong>exception</strong></p>
<pre>java.lang.NullPointerException</pre>
<p>Đây là dòng báo lỗi của em nó.</p>
<p>Và nguyên nhân là do trong lớp connectDB thiếu 1 dòng.</p>
<p>Trước là như vầy:</p>
<blockquote><p>Connection connection = null;<br />
try {<br />
connection = DriverManager.getConnection(&#8220;jdbc:postgresql://localhost:5432/caxxx&#8221;,&#8221;postgres&#8221;,&#8221;xxxxxx&#8221;);<br />
} catch (Exception e) {}<br />
return connection;</p></blockquote>
<p>Và sửa lại như thế này để chạy bình thường:</p>
<blockquote><p>Connection connection = null;<br />
try {<br />
Class.forName(&#8220;org.postgresql.Driver&#8221;);<br />
connection = DriverManager.getConnection(&#8220;jdbc:postgresql://localhost:5432/caxxxx&#8221;,&#8221;postgres&#8221;,&#8221;xxxxxx&#8221;);<br />
} catch (Exception e) {}<br />
return connection;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://phamcuong.info/2009/12/10/l%e1%bb%97i-connect-database-xa-x%c6%b0a-nh%c6%b0ng-gay-l%e1%bb%97i-500/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sử dụng captcha trong Struts</title>
		<link>http://phamcuong.info/2009/11/02/s%e1%bb%ad-d%e1%bb%a5ng-captcha-trong-struts/</link>
		<comments>http://phamcuong.info/2009/11/02/s%e1%bb%ad-d%e1%bb%a5ng-captcha-trong-struts/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 02:59:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Lập trình]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://phamcuong.info/?p=489</guid>
		<description><![CDATA[This Java Captcha Example demonstrates you how to develop a captcha Servlet and use in your Struts 2 application. Developing Struts 2 Captcha Application In this section we are going to develop Captcha Servlet and then use the same to validate Struts 2 based web applications. We have developed a Servlet that generates Captcha image. [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #000080;">This Java Captcha Example demonstrates you how to develop a captcha Servlet and use in your Struts 2 application.</span></p>
<p><span style="color: #000080;"><span id="more-489"></span><strong>Developing Struts 2 </strong></span><strong><span style="color: #000080;">Captcha </span></strong><span style="color: #000080;"><strong> Application<br />
</strong>In this section we are going to develop Captcha Servlet and then use the same to validate Struts 2 based web applications. We have developed a Servlet that generates Captcha image. </span></p>
<p>Let&#8217;s see how our Captcha <span style="color: #000080;">application works. </span></p>
<p><strong><span style="color: #000080;">Working of the application</span></strong></p>
<ol>
<li><span style="color: #000080;"><strong>captcha.jsp:</strong> This page contains the     captcha image and one text field. </span></li>
<li><span style="color: #000080;">User reads the image text and then enters in the     &#8220;Code&#8221; text field. After entering the value in the text field,     user clicks on the &#8220;<strong>Verify</strong>&#8220;      command button.</span></li>
<li><span style="color: #000080;">Then our Struts 2 action validates the user input     and the session Captcha value.  If user enters the correct image code in the text filed,     then action  forward to the &#8220;<strong>success.jsp</strong>&#8221;     page. Otherwise, it gives an error and go to again the &#8220;<strong>captcha.jsp</strong>&#8220;.</span></li>
</ol>
<p><span style="color: #000080;"><strong>1. Index page<br />
</strong>In the  <strong>index.html</strong> we have added a link to <strong>captcha.jsp.</strong> User can click on this link to go to the captcha form.</span></p>
<table border="0" cellspacing="1" cellpadding="0" width="301" bgcolor="#ffffcc">
<tbody>
<tr>
<td width="295"><span style="color: #000080;">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Capcha Validation&lt;/title&gt;<br />
&lt;style&gt;<br />
a:link{ color:red; text-decoration:underline; }<br />
a:visited{ color:red; text-decoration:underline; }<br />
a:hover{ color:green; text-decoration:none; }<br />
a:active{ color:red; text-decoration:underline; }<br />
&lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;table&gt;<br />
&lt;tr&gt;&lt;td&gt;<strong>&lt;a href=&#8221;captcha.jsp&#8221;&gt;Captcha Application&lt;/a&gt;</strong>&lt;/td&gt;&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000080;"><strong>2. Captcha Page </strong><br />
The GUI of the application consists of  Captcha page  (<strong>captcha.jsp</strong>).<br />
The <strong>captcha.jsp</strong> is used to display the valid code and a text box. </span></p>
<table border="0" cellspacing="1" cellpadding="0" width="413" bgcolor="#ffffcc">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code><span style="color: #000080;">&lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Capcha Validation&lt;/title&gt;<br />
&lt;style&gt;<br />
.errorMessage {<br />
color: red;<br />
font-size: 0.8em;<br />
}</p>
<p>.label {<br />
color:#000000;<br />
}<br />
&lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;table&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;<br />
&lt;h1&gt;Captcha Validation&lt;/h1&gt;<br />
&lt;s:form action="doCaptcha" method="POST"&gt;<br />
&lt;s:actionerror /&gt;<br />
&lt;img src="Captcha.jpg" border="0"&gt;<br />
&lt;s:textfield label="Code" name="j_captcha_response" size="20" maxlength="10"/&gt;<br />
&lt;s:submit value="Verify" align="center" /&gt;<br />
&lt;/s:form&gt;<br />
&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</span></code></td>
<p><!-- end source code --></tr>
</tbody>
</table>
<p><span style="color: #000080;">The code :<br />
<strong>&lt;s:actionerror /&gt;</strong><br />
displays action errors and field validation errors.</span></p>
<p><span style="color: #000080;">The code <strong>&lt;s:form action=&#8221;doLogin&#8221; method=&#8221;POST&#8221;&gt; </strong>generates the html form for the application.</p>
<p>The code :</span></p>
<p><span style="color: #000080;"><strong>&lt;img src=&#8221;Captcha.jpg&#8221; border=&#8221;0&#8243;&gt;</strong><br />
<strong>&lt;s:textfield label=&#8221;Code&#8221; name=&#8221;j_captcha_response&#8221; size=&#8221;20&#8243; maxlength=&#8221;10&#8243;/&gt;<br />
</strong></span></p>
<p><span style="color: #000080;">The submit button is generated through <strong>&lt;s:submit value=&#8221;Verify&#8221; align=&#8221;center&#8221; /&gt;</strong> code.</span></p>
<p><span style="color: #000080;"><strong>3. Servlet Class<br />
</strong>Develop a Servlet class &#8220;<strong>RoseIndiaCaptcha.java</strong>&#8221; to create a Captcha image. Here is the code of <strong> RoseIndiaCaptcha.java</strong> Servlet class:</span></p>
<table border="0" cellspacing="1" cellpadding="0" width="300" bgcolor="#ffffcc">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code> <span style="color: #000080;"><strong>package </strong>com.roseindiaCaptcha.servlet;</p>
<p><strong>import </strong>java.awt.image.BufferedImage;<br />
<strong>import </strong>javax.imageio.ImageIO;<br />
<strong>import </strong>javax.servlet.http.*;<br />
<strong>import </strong>javax.servlet.*;<br />
<strong>import </strong>java.io.*;<br />
<strong>import </strong>java.awt.*;<br />
<strong>import </strong>java.util.*;<br />
<strong>import </strong>java.awt.font.TextAttribute;</p>
<p><strong>public class </strong>RoseIndiaCaptcha <strong>extends </strong>HttpServlet {</p>
<p><strong>private int </strong>height=0;<br />
<strong>private int </strong>width=0;</p>
<p><strong>public static final </strong>String CAPTCHA_KEY = "captcha_key_name";</p>
<p><strong>public void </strong>init(ServletConfig config) <strong>throws </strong>ServletException {<br />
<strong>super</strong>.init(config);<br />
height=Integer.parseInt(getServletConfig().getInitParameter("height"));<br />
width=Integer.parseInt(getServletConfig().getInitParameter("width"));<br />
}</p>
<p><strong>protected void </strong>doGet(HttpServletRequest req, HttpServletResponse response)<br />
<strong>throws </strong>IOException, ServletException {<br />
//Expire response<br />
response.setHeader("Cache-Control", "no-cache");<br />
response.setDateHeader("Expires", 0);<br />
response.setHeader("Pragma", "no-cache");<br />
response.setDateHeader("Max-Age", 0);</p>
<p>BufferedImage image = <strong>new </strong>BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);<br />
Graphics2D graphics2D = image.createGraphics();<br />
Hashtable&lt;TextAttribute, Object&gt; map = <strong>new </strong>Hashtable&lt;TextAttribute, Object&gt;();<br />
Random r = <strong>new </strong>Random();<br />
String token = Long.toString(Math.abs(r.nextLong()), 36);<br />
String ch = token.substring(0,6);<br />
Color c = <strong>new </strong>Color(0.6662f, 0.4569f, 0.3232f);<br />
GradientPaint gp = <strong>new </strong>GradientPaint(30, 30, c, 15, 25, Color.white, <strong>true</strong>);<br />
graphics2D.setPaint(gp);<br />
Font font=<strong>new </strong>Font("Verdana", Font.CENTER_BASELINE , 26);<br />
graphics2D.setFont(font);<br />
graphics2D.drawString(ch,2,20);<br />
graphics2D.dispose();</p>
<p>HttpSession session = req.getSession(<strong>true</strong>);<br />
session.setAttribute(CAPTCHA_KEY,ch);</p>
<p>OutputStream outputStream = response.getOutputStream();<br />
ImageIO.write(image, "jpeg", outputStream);<br />
outputStream.close();</p>
<p>}</p>
<p>}</span></code></td>
<p><!-- end source code --></tr>
</tbody>
</table>
<p><strong><span style="color: #000080;">4.Mapping  for Servlet class in web.xml</span></strong></p>
<table border="0" cellspacing="1" cellpadding="0" width="618" bgcolor="#ffffcc">
<tbody>
<tr>
<td width="612">&lt;servlet&gt;<br />
&lt;servlet-name&gt;Captcha&lt;/servlet-name&gt;<br />
&lt;display-name&gt;Captcha&lt;/display-name&gt;<br />
<strong>&lt;servlet-class&gt;com.roseindiaCaptcha.servlet.RoseIndiaCaptcha&lt;/servlet-class&gt;</strong><br />
&lt;init-param&gt;<br />
&lt;description&gt;passing height&lt;/description&gt;<br />
&lt;param-name&gt;height&lt;/param-name&gt;<br />
&lt;param-value&gt;30&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
&lt;init-param&gt;<br />
&lt;description&gt;passing height&lt;/description&gt;<br />
&lt;param-name&gt;width&lt;/param-name&gt;<br />
&lt;param-value&gt;120&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
&lt;/servlet&gt;</p>
<p>&lt;servlet-mapping&gt;<br />
&lt;servlet-name&gt;Captcha&lt;/servlet-name&gt;<br />
<strong>&lt;url-pattern&gt;/Captcha.jpg&lt;/url-pattern&gt;</strong><br />
&lt;/servlet-mapping&gt;</td>
</tr>
</tbody>
</table>
<p><strong><span style="color: #000080;">5.Success page</span></strong></p>
<p><span style="color: #000080;">After successful validation page  transfer to the <strong>&#8220;success.page&#8221;</strong></span></p>
<table border="0" cellspacing="1" cellpadding="0" width="300" bgcolor="#ffffcc">
<tbody>
<tr>
<td><span style="color: #000080;">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Capcha Validation&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;h1&gt;You are Succesfully Validate&lt;/h1&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000080;"><strong>6.Developing Action Class</strong><br />
Now let&#8217;s develop the action class to handle the Captcha validation request. </span></p>
<p><span style="color: #000080;">The code  <strong>String c= (String)session.getAttribute(RoseIndiaCaptcha.CAPTCHA_KEY)</strong> is used to get the Captcha value stored in session and then validate it with the user input. Here is the code of the Action class.</span></p>
<table border="0" cellspacing="1" cellpadding="0" width="300" bgcolor="#ffffcc">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code> <span style="color: #000080;"><strong>package </strong>com.roseindiaCaptcha.action;<br />
<strong>import </strong>com.opensymphony.xwork2.ActionSupport;<br />
<strong>import </strong>java.util.Date;<br />
<strong>import </strong>javax.servlet.http.*;<br />
<strong>import </strong>javax.servlet.*;<br />
<strong>import </strong>com.opensymphony.xwork2.ActionContext;<br />
<strong>import </strong>com.roseindiaCaptcha.servlet.*;</p>
<p><strong>public  class </strong>CaptchaAction  <strong>extends </strong>ActionSupport {<br />
<strong>public </strong>String execute() <strong>throws </strong>Exception {<br />
HttpServletRequest request  = (HttpServletRequest)<br />
ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);<br />
Boolean isResponseCorrect = Boolean.FALSE;<br />
javax.servlet.http.HttpSession session = request.getSession();<br />
String parm = request.getParameter("j_captcha_response");<br />
String c= (String)session.getAttribute(RoseIndiaCaptcha.CAPTCHA_KEY) ;<br />
<strong>if</strong>(!parm.equals(c) ){<br />
addActionError("Invalid Code! Please try again!");<br />
<strong>return </strong>ERROR;<br />
}<strong>else</strong>{<br />
<strong>return </strong>SUCCESS;<br />
}<br />
}<br />
}</span></code></td>
<p><!-- end source code --></tr>
</tbody>
</table>
<p><strong><span style="color: #000080;"> </span></strong></p>
<p><span style="color: #000080;"><strong>7.Configuring action mapping (in struts.xml)</strong><br />
Now we will create action mapping in the struts.xml file. Here is the code to be added in the struts.xml:<br />
</span></p>
<div>
<table border="1" cellspacing="0" cellpadding="0" width="400" bgcolor="#ffffcc" bordercolor="#c0c0c0">
<tbody>
<tr>
<td><span style="color: #000080;">&lt;action name=&#8221;doCaptcha&#8221; class=&#8221;com.roseindiaCaptcha.action.CaptchaAction&#8221;&gt;<br />
&lt;result name=&#8221;error&#8221;&gt;captcha.jsp&lt;/result&gt;<br />
&lt;result&gt;success.jsp&lt;/result&gt;<br />
&lt;/action&gt;</span></td>
</tr>
</tbody>
</table>
</div>
<p><span style="color: #000080;">In the above mapping the action &#8220;doCaptcha&#8221; is used to validates the user using action class (CaptchaAction.java).</span></p>
<p><span style="color: #000080;"><strong>Output : </strong></span></p>
<p><img src="http://www.roseindia.net/struts/struts2/captcha/captchaLink.gif" border="1" alt="" width="155" height="44" /><br />
<img src="http://www.roseindia.net/struts/struts2/captcha/captcha.gif" border="1" alt="" width="285" height="152" /></p>
<p><span style="color: #000080;">If invalid code the error message is display.</span></p>
<p><span style="color: #000080;"><img src="http://www.roseindia.net/struts/struts2/captcha/error.gif" border="1" alt="" width="290" height="188" /></span></p>
<p><span style="color: #000080;"><img src="http://www.roseindia.net/struts/struts2/captcha/valid.gif" border="1" alt="" width="285" height="150" /><br />
</span></p>
<p><span style="color: #000080;">After successfully validation message :</span></p>
<p><span style="color: #000080;"><img src="http://www.roseindia.net/struts/struts2/captcha/successmsg.gif" border="1" alt="" width="422" height="47" /></span></p>
<p><span style="color: #000080;"><strong> </strong> <strong><br />
<a href="http://www.roseindia.net/struts/struts2/captcha/roseindiaCaptcha.zip">Download the application</a> </strong></span></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td rowspan="2" width="125" align="center" valign="top">
<table style="border-style: solid; border-color: #d4d5d6; border-width: 0px 0px 0px 1px;" border="0" cellspacing="0" cellpadding="2" width="125">
<tbody>
<tr>
<td align="left" valign="top">
<ul class="categorylinks">
<li id="c7"></li>
</ul>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="headers">
<div></div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="2" width="99%" height="380" align="left" valign="top">
<div class="border-1">
<table border="0" cellspacing="0" cellpadding="0" width="800">
<tbody>
<tr>
<td colspan="3" align="left" valign="top" bgcolor="#ccff99">
<strong><span style="font-family: Arial; font-size: small;">Java Captcha in Struts 2 Application</span></strong></td>
</tr>
<tr>
<td colspan="3" align="left" valign="top">
<span style="font-family: Arial; color: #000080; font-size: x-small;">This Java Captcha Example demonstrates you how to develop a captcha Servlet and use in your Struts 2 application.</span></td>
</tr>
<tr>
<td width="336" align="center" valign="middle"><script type="text/javascript">// <![CDATA[
google_ad_client = "pub-0714075272818912";
/* 336x280, created 1/28/09Top-336x280 */
google_ad_slot = "4891982402";
google_ad_width = 336;
google_ad_height = 280;
// ]]&gt;</script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script><script src="http://pagead2.googlesyndication.com/pagead/expansion_embed.js"></script><script src="http://googleads.g.doubleclick.net/pagead/test_domain.js"></script><script type="text/javascript">// <![CDATA[
google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);
// ]]&gt;</script><ins style="border: medium none; margin: 0pt; padding: 0pt; display: inline-table; height: 280px; position: relative; visibility: visible; width: 336px;"><ins style="border: medium none; margin: 0pt; padding: 0pt; display: block; height: 280px; position: relative; visibility: visible; width: 336px;"></ins></ins></td>
<td align="left" valign="middle"><script type="text/javascript">// <![CDATA[
google_ad_client = "pub-0714075272818912";
/* Top 336x280, -2- created 10/19/09 */
google_ad_slot = "8054255732";
google_ad_width = 336;
google_ad_height = 280;
// ]]&gt;</script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script><script type="text/javascript">// <![CDATA[
google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);
// ]]&gt;</script><ins style="border: medium none; margin: 0pt; padding: 0pt; display: inline-table; height: 280px; position: relative; visibility: visible; width: 336px;"><ins style="border: medium none; margin: 0pt; padding: 0pt; display: block; height: 280px; position: relative; visibility: visible; width: 336px;"></ins></ins></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<td width="90%" valign="top"><!-- google_ad_section_start --> <!-- Top --> <!-- Left --></p>
<div>
<table border="0" width="98%">
<tbody>
<tr>
<td width="100%" align="left">
<h1><span style="color: #000080;">Java Captcha in Struts 2	 Application</span></h1>
<p align="center">
<div class="adsBelowHeadingNormal"><script type="text/javascript">// <![CDATA[
google_ad_client = "pub-0714075272818912";
/* 336x280, created 2/11/08 LeftNewAds */
google_ad_slot = "1009602866";
google_ad_width = 336;
google_ad_height = 280;
// ]]&gt;</script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script><script type="text/javascript">// <![CDATA[
google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);
// ]]&gt;</script><ins style="border: medium none; margin: 0pt; padding: 0pt; display: inline-table; height: 280px; position: relative; visibility: visible; width: 336px;"><ins style="border: medium none; margin: 0pt; padding: 0pt; display: block; height: 280px; position: relative; visibility: visible; width: 336px;"></ins></ins></div>
<p><a href="http://www.roseindia.net/struts/struts2/captcha/java-captcha-example.shtml"><img src="http://www.roseindia.net/images/previous.gif" border="0" alt="" /></a> <a href="http://www.roseindia.net/struts/struts2/captcha/index.shtml"><img src="http://www.roseindia.net/images/bt_home.gif" border="0" alt="" /></a> <a href="http://www.roseindia.net/struts/struts2/captcha/java-captcha-example.shtml"><img src="http://www.roseindia.net/images/next.gif" border="0" alt="" /></a><span style="color: #000080;">This Java Captcha Example demonstrates you how to develop a captcha Servlet and use in your Struts 2 application.</span></p>
<p><span style="color: #000080;"><strong>Developing Struts 2 </strong></span><strong><span style="color: #000080;">Captcha </span></strong><span style="color: #000080;"><strong> Application<br />
</strong>In this section we are going to develop Captcha Servlet and then use the same to validate Struts 2 based web applications. We have developed a Servlet that generates Captcha image. </span></p>
<p>Let&#8217;s see how our Captcha <span style="color: #000080;">application works. </span></p>
<p><strong><span style="color: #000080;">Working of the application</span></strong></p>
<ol>
<li><span style="color: #000080;"><strong>captcha.jsp:</strong> This page contains the     captcha image and one text field. </span></li>
<li><span style="color: #000080;">User reads the image text and then enters in the     &#8220;Code&#8221; text field. After entering the value in the text field,     user clicks on the &#8220;<strong>Verify</strong>&#8220;      command button.</span></li>
<li><span style="color: #000080;">Then our Struts 2 action validates the user input     and the session Captcha value.  If user enters the correct image code in the text filed,     then action  forward to the &#8220;<strong>success.jsp</strong>&#8221;     page. Otherwise, it gives an error and go to again the &#8220;<strong>captcha.jsp</strong>&#8220;.</span></li>
</ol>
<p><span style="color: #000080;"><strong>1. Index page<br />
</strong>In the  <strong>index.html</strong> we have added a link to <strong>captcha.jsp.</strong> User can click on this link to go to the captcha form.</span></p>
<table border="0" cellspacing="1" cellpadding="0" width="301" bgcolor="#ffffcc">
<tbody>
<tr>
<td width="295"><span style="color: #000080;">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Capcha Validation&lt;/title&gt;<br />
&lt;style&gt;<br />
a:link{ color:red; text-decoration:underline; }<br />
a:visited{ color:red; text-decoration:underline; }<br />
a:hover{ color:green; text-decoration:none; }<br />
a:active{ color:red; text-decoration:underline; }<br />
&lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;table&gt;<br />
&lt;tr&gt;&lt;td&gt;<strong>&lt;a href=&#8221;captcha.jsp&#8221;&gt;Captcha Application&lt;/a&gt;</strong>&lt;/td&gt;&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000080;"><strong>2. Captcha Page </strong><br />
The GUI of the application consists of  Captcha page  (<strong>captcha.jsp</strong>).<br />
The <strong>captcha.jsp</strong> is used to display the valid code and a text box. </span></p>
<table border="0" cellspacing="1" cellpadding="0" width="413" bgcolor="#ffffcc">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code><span style="color: #000080;">&lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Capcha Validation&lt;/title&gt;<br />
&lt;style&gt;<br />
.errorMessage {<br />
color: red;<br />
font-size: 0.8em;<br />
}</p>
<p>.label {<br />
color:#000000;<br />
}<br />
&lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;table&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;<br />
&lt;h1&gt;Captcha Validation&lt;/h1&gt;<br />
&lt;s:form action="doCaptcha" method="POST"&gt;<br />
&lt;s:actionerror /&gt;<br />
&lt;img src="Captcha.jpg" border="0"&gt;<br />
&lt;s:textfield label="Code" name="j_captcha_response" size="20" maxlength="10"/&gt;<br />
&lt;s:submit value="Verify" align="center" /&gt;<br />
&lt;/s:form&gt;<br />
&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</span></code></td>
<p><!-- end source code --></tr>
</tbody>
</table>
<p><span style="color: #000080;">The code :<br />
<strong>&lt;s:actionerror /&gt;</strong><br />
displays action errors and field validation errors.</span></p>
<p><span style="color: #000080;">The code <strong>&lt;s:form action=&#8221;doLogin&#8221; method=&#8221;POST&#8221;&gt; </strong>generates the html form for the application.</p>
<p>The code :</span></p>
<p><span style="color: #000080;"><strong>&lt;img src=&#8221;Captcha.jpg&#8221; border=&#8221;0&#8243;&gt;</strong><br />
<strong>&lt;s:textfield label=&#8221;Code&#8221; name=&#8221;j_captcha_response&#8221; size=&#8221;20&#8243; maxlength=&#8221;10&#8243;/&gt;<br />
</strong></span></p>
<p><span style="color: #000080;">The submit button is generated through <strong>&lt;s:submit value=&#8221;Verify&#8221; align=&#8221;center&#8221; /&gt;</strong> code.</span></p>
<p><span style="color: #000080;"><strong>3. Servlet Class<br />
</strong>Develop a Servlet class &#8220;<strong>RoseIndiaCaptcha.java</strong>&#8221; to create a Captcha image. Here is the code of <strong> RoseIndiaCaptcha.java</strong> Servlet class:</span></p>
<table border="0" cellspacing="1" cellpadding="0" width="300" bgcolor="#ffffcc">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code> <span style="color: #000080;"><strong>package </strong>com.roseindiaCaptcha.servlet;</p>
<p><strong>import </strong>java.awt.image.BufferedImage;<br />
<strong>import </strong>javax.imageio.ImageIO;<br />
<strong>import </strong>javax.servlet.http.*;<br />
<strong>import </strong>javax.servlet.*;<br />
<strong>import </strong>java.io.*;<br />
<strong>import </strong>java.awt.*;<br />
<strong>import </strong>java.util.*;<br />
<strong>import </strong>java.awt.font.TextAttribute;</p>
<p><strong>public class </strong>RoseIndiaCaptcha <strong>extends </strong>HttpServlet {</p>
<p><strong>private int </strong>height=0;<br />
<strong>private int </strong>width=0;</p>
<p><strong>public static final </strong>String CAPTCHA_KEY = "captcha_key_name";</p>
<p><strong>public void </strong>init(ServletConfig config) <strong>throws </strong>ServletException {<br />
<strong>super</strong>.init(config);<br />
height=Integer.parseInt(getServletConfig().getInitParameter("height"));<br />
width=Integer.parseInt(getServletConfig().getInitParameter("width"));<br />
}</p>
<p><strong>protected void </strong>doGet(HttpServletRequest req, HttpServletResponse response)<br />
<strong>throws </strong>IOException, ServletException {<br />
//Expire response<br />
response.setHeader("Cache-Control", "no-cache");<br />
response.setDateHeader("Expires", 0);<br />
response.setHeader("Pragma", "no-cache");<br />
response.setDateHeader("Max-Age", 0);</p>
<p>BufferedImage image = <strong>new </strong>BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);<br />
Graphics2D graphics2D = image.createGraphics();<br />
Hashtable&lt;TextAttribute, Object&gt; map = <strong>new </strong>Hashtable&lt;TextAttribute, Object&gt;();<br />
Random r = <strong>new </strong>Random();<br />
String token = Long.toString(Math.abs(r.nextLong()), 36);<br />
String ch = token.substring(0,6);<br />
Color c = <strong>new </strong>Color(0.6662f, 0.4569f, 0.3232f);<br />
GradientPaint gp = <strong>new </strong>GradientPaint(30, 30, c, 15, 25, Color.white, <strong>true</strong>);<br />
graphics2D.setPaint(gp);<br />
Font font=<strong>new </strong>Font("Verdana", Font.CENTER_BASELINE , 26);<br />
graphics2D.setFont(font);<br />
graphics2D.drawString(ch,2,20);<br />
graphics2D.dispose();</p>
<p>HttpSession session = req.getSession(<strong>true</strong>);<br />
session.setAttribute(CAPTCHA_KEY,ch);</p>
<p>OutputStream outputStream = response.getOutputStream();<br />
ImageIO.write(image, "jpeg", outputStream);<br />
outputStream.close();</p>
<p>}</p>
<p>}</span></code></td>
<p><!-- end source code --></tr>
</tbody>
</table>
<p><strong><span style="color: #000080;">4.Mapping  for Servlet class in web.xml</span></strong></p>
<table border="0" cellspacing="1" cellpadding="0" width="618" bgcolor="#ffffcc">
<tbody>
<tr>
<td width="612">&lt;servlet&gt;<br />
&lt;servlet-name&gt;Captcha&lt;/servlet-name&gt;<br />
&lt;display-name&gt;Captcha&lt;/display-name&gt;<br />
<strong>&lt;servlet-class&gt;com.roseindiaCaptcha.servlet.RoseIndiaCaptcha&lt;/servlet-class&gt;</strong><br />
&lt;init-param&gt;<br />
&lt;description&gt;passing height&lt;/description&gt;<br />
&lt;param-name&gt;height&lt;/param-name&gt;<br />
&lt;param-value&gt;30&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
&lt;init-param&gt;<br />
&lt;description&gt;passing height&lt;/description&gt;<br />
&lt;param-name&gt;width&lt;/param-name&gt;<br />
&lt;param-value&gt;120&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
&lt;/servlet&gt;</p>
<p>&lt;servlet-mapping&gt;<br />
&lt;servlet-name&gt;Captcha&lt;/servlet-name&gt;<br />
<strong>&lt;url-pattern&gt;/Captcha.jpg&lt;/url-pattern&gt;</strong><br />
&lt;/servlet-mapping&gt;</td>
</tr>
</tbody>
</table>
<p><strong><span style="color: #000080;">5.Success page</span></strong></p>
<p><span style="color: #000080;">After successful validation page  transfer to the <strong>&#8220;success.page&#8221;</strong></span></p>
<table border="0" cellspacing="1" cellpadding="0" width="300" bgcolor="#ffffcc">
<tbody>
<tr>
<td><span style="color: #000080;">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Capcha Validation&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;h1&gt;You are Succesfully Validate&lt;/h1&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="color: #000080;"><strong>6.Developing Action Class</strong><br />
Now let&#8217;s develop the action class to handle the Captcha validation request. </span></p>
<p><span style="color: #000080;">The code  <strong>String c= (String)session.getAttribute(RoseIndiaCaptcha.CAPTCHA_KEY)</strong> is used to get the Captcha value stored in session and then validate it with the user input. Here is the code of the Action class.</span></p>
<table border="0" cellspacing="1" cellpadding="0" width="300" bgcolor="#ffffcc">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code> <span style="color: #000080;"><strong>package </strong>com.roseindiaCaptcha.action;<br />
<strong>import </strong>com.opensymphony.xwork2.ActionSupport;<br />
<strong>import </strong>java.util.Date;<br />
<strong>import </strong>javax.servlet.http.*;<br />
<strong>import </strong>javax.servlet.*;<br />
<strong>import </strong>com.opensymphony.xwork2.ActionContext;<br />
<strong>import </strong>com.roseindiaCaptcha.servlet.*;</p>
<p><strong>public  class </strong>CaptchaAction  <strong>extends </strong>ActionSupport {<br />
<strong>public </strong>String execute() <strong>throws </strong>Exception {<br />
HttpServletRequest request  = (HttpServletRequest)<br />
ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);<br />
Boolean isResponseCorrect = Boolean.FALSE;<br />
javax.servlet.http.HttpSession session = request.getSession();<br />
String parm = request.getParameter("j_captcha_response");<br />
String c= (String)session.getAttribute(RoseIndiaCaptcha.CAPTCHA_KEY) ;<br />
<strong>if</strong>(!parm.equals(c) ){<br />
addActionError("Invalid Code! Please try again!");<br />
<strong>return </strong>ERROR;<br />
}<strong>else</strong>{<br />
<strong>return </strong>SUCCESS;<br />
}<br />
}<br />
}</span></code></td>
<p><!-- end source code --></tr>
</tbody>
</table>
<p><strong><span style="color: #000080;"> </span></strong></p>
<p><span style="color: #000080;"><strong>7.Configuring action mapping (in struts.xml)</strong><br />
Now we will create action mapping in the struts.xml file. Here is the code to be added in the struts.xml:<br />
</span></p>
<div>
<table border="1" cellspacing="0" cellpadding="0" width="400" bgcolor="#ffffcc" bordercolor="#c0c0c0">
<tbody>
<tr>
<td><span style="color: #000080;">&lt;action name=&#8221;doCaptcha&#8221; class=&#8221;com.roseindiaCaptcha.action.CaptchaAction&#8221;&gt;<br />
&lt;result name=&#8221;error&#8221;&gt;captcha.jsp&lt;/result&gt;<br />
&lt;result&gt;success.jsp&lt;/result&gt;<br />
&lt;/action&gt;</span></td>
</tr>
</tbody>
</table>
</div>
<p><span style="color: #000080;">In the above mapping the action &#8220;doCaptcha&#8221; is used to validates the user using action class (CaptchaAction.java).</span></p>
<p><span style="color: #000080;"><strong>Output : </strong></span></p>
<p><img src="http://www.roseindia.net/struts/struts2/captcha/captchaLink.gif" border="1" alt="" width="155" height="44" /><br />
<img src="http://www.roseindia.net/struts/struts2/captcha/captcha.gif" border="1" alt="" width="285" height="152" /></p>
<p><span style="color: #000080;">If invalid code the error message is display.</span></p>
<p><span style="color: #000080;"><img src="http://www.roseindia.net/struts/struts2/captcha/error.gif" border="1" alt="" width="290" height="188" /></span></p>
<p><span style="color: #000080;"><img src="http://www.roseindia.net/struts/struts2/captcha/valid.gif" border="1" alt="" width="285" height="150" /><br />
</span></p>
<p><span style="color: #000080;">After successfully validation message :</span></p>
<p><span style="color: #000080;"><img src="http://www.roseindia.net/struts/struts2/captcha/successmsg.gif" border="1" alt="" width="422" height="47" /></span></p>
<p><span style="color: #000080;"><strong> </strong> <strong><br />
<a href="http://www.roseindia.net/struts/struts2/captcha/roseindiaCaptcha.zip">Download the application</a> </strong></span></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://phamcuong.info/2009/11/02/s%e1%bb%ad-d%e1%bb%a5ng-captcha-trong-struts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sử dụng Struts trong java</title>
		<link>http://phamcuong.info/2009/11/01/s%e1%bb%ad-d%e1%bb%a5ng-struts-trong-java/</link>
		<comments>http://phamcuong.info/2009/11/01/s%e1%bb%ad-d%e1%bb%a5ng-struts-trong-java/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 01:18:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Lập trình]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://phamcuong.info/?p=478</guid>
		<description><![CDATA[Cách để làm việc nhẹ nhàng hơn với nhập liệu trong dịch vụ web của JSP. Thư viện: •Tải về từ địa chỉ sau: http://www.mediafire.com/download.php?izk3yht5nyo Bao gồm (tối thiểu để chạy struts): Cách cài đặt: file struts &#60;!DOCTYPE struts PUBLIC &#8220;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#8221; &#8220;http://struts.apache.org/dtds/struts-2.0.dtd&#8221;&#62; &#60;struts&#62; &#60;package name=&#8221;default&#8221; extends=&#8221;struts-default&#8221;&#62; &#60;action name=&#8221;HelloWorld&#8221;&#62; &#60;result name=&#8221;SUCCESS&#8221;&#62;/success.jsp&#60;/result&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Cách để làm việc nhẹ nhàng hơn với nhập liệu trong dịch vụ web của JSP.<span id="more-478"></span></p>
<p><strong>Thư viện:</strong></p>
<p>•Tải về từ địa chỉ sau:</p>
<p>http://www.mediafire.com/download.php?izk3yht5nyo</p>
<p>Bao gồm (tối thiểu để chạy struts):</p>
<p><img src="http://i458.photobucket.com/albums/qq304/camovie/struts.jpg" border="0" alt="Photobucket" /></p>
<blockquote><p><strong>Cách cài đặt: file struts</strong></p>
<p>&lt;!DOCTYPE struts PUBLIC</p>
<p>&#8220;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#8221;</p>
<p>&#8220;http://struts.apache.org/dtds/struts-2.0.dtd&#8221;&gt;</p>
<p>&lt;struts&gt;</p>
<p>&lt;package name=&#8221;default&#8221; extends=&#8221;struts-default&#8221;&gt;</p>
<p>&lt;action name=&#8221;HelloWorld&#8221;&gt;</p>
<p>&lt;result name=&#8221;SUCCESS&#8221;&gt;/success.jsp&lt;/result&gt;</p>
<p>&lt;/action&gt;</p>
<p>&lt;/package&gt;</p>
<p>&lt;/struts&gt;</p></blockquote>
<p>File này nằm trong thư mục gốc của thư mục src ( thư mục chứa file java)</p>
<p><strong>Cách cài đặt</strong>: thêm vào file web.xml</p>
<p>&lt;filter&gt;</p>
<p>&lt;filter-name&gt;struts2&lt;/filter-name&gt;</p>
<p>&lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt;</p>
<p>&lt;/filter&gt;</p>
<p>&lt;filter-mapping&gt;</p>
<p>&lt;filter-name&gt;struts2&lt;/filter-name&gt;</p>
<p>&lt;url-pattern&gt;/*&lt;/url-pattern&gt;</p>
<p>&lt;/filter-mapping&gt;</p>
<p><strong>Cách sử dụng: form struts</strong></p>
<p>Khai báo taglib như thẻ c (jstl)</p>
<p>&lt;%@taglib uri=&#8221;/struts-tags&#8221; prefix=&#8221;s&#8221; %&gt;</p>
<p>Ví dụ:</p>
<p>&lt;s:form action=&#8221;HelloWorld&#8221; &gt;</p>
<p>&lt;s:textfield name=&#8221;userName&#8221; label=&#8221;User Name&#8221; /&gt;</p>
<p>&lt;s:submit /&gt;</p>
<p>&lt;/s:form&gt;</p>
<p>Có thể kô sử dụng taglib, nhưng trong form, thẻ action thì bắt buộc tên action có thêm đuôi .action</p>
<p>Ví dụ:</p>
<p>Thay &lt;form action=“Hello” … &gt;</p>
<p>Thành &lt;form action=“Hello.action” …&gt;</p>
<p>Cách sử dụng: lớp action</p>
<p>Tạo mới lớp java bình thường: Biến nhận vào phải giống với name trong input ở thẻ form.</p>
<p>Biến phải có đầy đủ getter và setter. Chỉ được thao tác với biến qua getter và setter.</p>
<p>Ví dụ:</p>
<p>Biến String name;</p>
<p>Chỉ được gọi getName() kô được dùng name</p>
<p>Hiện thực phương thức:</p>
<p>public String execute() {};</p>
<p>Sẽ viết sử lý của lớp action trong đây.</p>
<p>Trả về có 2 mặc định là:</p>
<p><span style="color: #0000ff;">Return SUCCESS</span>; (nếu đúng)</p>
<p><span style="color: #ff0000;">Return INPUT;</span> (nếu có sai sót)</p>
<p><strong>Cấu hình: file struts</strong></p>
<p>Mỗi action đều fải khai báo với file struts</p>
<p>Thêm vào:</p>
<p>&lt;action name=&#8221;HelloWorld&#8221;&gt;</p>
<p>&lt;result name=&#8221;SUCCESS&#8221;&gt;/success.jsp&lt;/result&gt;</p>
<p>&lt;/action&gt;</p>
<p>Tương ứng với trả về trong file action thì sẽ trỏ địa chỉ trang trả về.</p>
<p>Xem ví dụ ở: http://www.vaannila.com/struts-2/struts-2-example/struts-2-example.html</p>
]]></content:encoded>
			<wfw:commentRss>http://phamcuong.info/2009/11/01/s%e1%bb%ad-d%e1%bb%a5ng-struts-trong-java/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>lỗi không viết được servlet trong java trên eclipse</title>
		<link>http://phamcuong.info/2009/05/16/l%e1%bb%97i-khong-vi%e1%ba%bft-d%c6%b0%e1%bb%a3c-servlet-trong-java-tren-eclipse/</link>
		<comments>http://phamcuong.info/2009/05/16/l%e1%bb%97i-khong-vi%e1%ba%bft-d%c6%b0%e1%bb%a3c-servlet-trong-java-tren-eclipse/#comments</comments>
		<pubDate>Sat, 16 May 2009 04:18:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Lập trình]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[servlet]]></category>

		<guid isPermaLink="false">http://phamcuong.info/?p=6</guid>
		<description><![CDATA[Nếu bạn khởi tạo file servlet trong java mà không được, là do chưa add thư viện cho eclipes. Các bạn thêm thư viện như sau:]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter" title="Lỗi servlet" src="http://img2.pict.com/3c/f5/b2/6878cc95f2191cec0b98c51881/f0uUi/loi1.jpg" alt="" width="608" height="465" /></p>
<p>Nếu bạn khởi tạo file servlet trong java mà không được, là do chưa add thư viện cho eclipes.<span id="more-6"></span></p>
<p>Các bạn thêm thư viện như sau:</p>
<p><img src="http://img2.pict.com/62/5f/a7/a020b771b5b13d7a539142e57b/9WZI8/loi2.jpg" alt="" /></p>
<p><img src="http://img2.pict.com/79/71/a6/134c7d5195e293d01228f0bb6e/gnsBH/loi3.jpg" alt="" /></p>
<p><img src="http://img2.pict.com/80/d1/4a/ce4253ae9ad747dd9dffe8ba75/4vsaZ/loi4.jpg" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://phamcuong.info/2009/05/16/l%e1%bb%97i-khong-vi%e1%ba%bft-d%c6%b0%e1%bb%a3c-servlet-trong-java-tren-eclipse/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
