﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-yxc's java home-随笔分类-MyEclipse</title><link>http://www.blogjava.net/yxc0433/category/32711.html</link><description>If you want to know what can be everything? The answer is java!</description><language>zh-cn</language><lastBuildDate>Wed, 02 Jul 2008 20:51:36 GMT</lastBuildDate><pubDate>Wed, 02 Jul 2008 20:51:36 GMT</pubDate><ttl>60</ttl><item><title>实现一个简单的struts2应用（实现登陆）</title><link>http://www.blogjava.net/yxc0433/archive/2008/05/15/200545.html</link><dc:creator>yxc</dc:creator><author>yxc</author><pubDate>Wed, 14 May 2008 17:12:00 GMT</pubDate><guid>http://www.blogjava.net/yxc0433/archive/2008/05/15/200545.html</guid><wfw:comment>http://www.blogjava.net/yxc0433/comments/200545.html</wfw:comment><comments>http://www.blogjava.net/yxc0433/archive/2008/05/15/200545.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yxc0433/comments/commentRss/200545.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yxc0433/services/trackbacks/200545.html</trackback:ping><description><![CDATA[<img src="http://www.blogjava.net/images/blogjava_net/yxc0433/1.JPG" alt="" border="0" /><br />
今天我用myeclipse做了一个关于struts2的小例子，和大家分享当然工程新建和服务器配置就不多说了！导入stuts2 的 jar包也不多说了！<br />
首先配置web-inf下的web.xml<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">web-app&nbsp;</span><span style="color: rgb(255, 0, 0);">version</span><span style="color: rgb(0, 0, 255);">="2.4"</span><span style="color: rgb(255, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;xmlns</span><span style="color: rgb(0, 0, 255);">="http://java.sun.com/xml/ns/j2ee"</span><span style="color: rgb(255, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsi</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: rgb(255, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;xsi:schemaLocation</span><span style="color: rgb(0, 0, 255);">="http://java.sun.com/xml/ns/j2ee<br />
&nbsp;&nbsp;&nbsp;&nbsp;http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">filter</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">filter-name</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">struts2</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">filter-name</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">filter-class</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">org.apache.struts2.dispatcher.FilterDispatcher</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">filter-class</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">filter</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">filter-mapping</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">filter-name</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">struts2</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">filter-name</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">url-pattern</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">/*</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">url-pattern</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">filter-mapping</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">web-app</span><span style="color: rgb(0, 0, 255);">&gt;</span></div>
<br />
<br />
<br />
<br />
右击src建立并配置struts.xml&nbsp;&nbsp; <br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"&nbsp;</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE&nbsp;struts&nbsp;PUBLIC<br />
&nbsp;&nbsp;&nbsp;&nbsp;"-//Apache&nbsp;Software&nbsp;Foundation//DTD&nbsp;Struts&nbsp;Configuration&nbsp;2.0//EN"<br />
&nbsp;&nbsp;&nbsp;&nbsp;"http://struts.apache.org/dtds/struts-2.0.dtd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">struts</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">package&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="struts2"</span><span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;extends</span><span style="color: rgb(0, 0, 255);">="struts-default"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">action&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="login"</span><span style="color: rgb(255, 0, 0);">&nbsp;class</span><span style="color: rgb(0, 0, 255);">="com.test.action.LoginAction"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">result&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="input"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">login2.jsp</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">/result.jsp</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">result&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="failer"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">/login2.jsp</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">action</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">package</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">struts</span><span style="color: rgb(0, 0, 255);">&gt;</span></div>
<br />
<br />
<br />
并在src目录下建立包com.test.action,里面新建一个java类LoginAction.java<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;*Coryright(c)2008&nbsp;yxc&nbsp;&amp;&nbsp;njust<br />
&nbsp;*All&nbsp;rights&nbsp;reserved.<br />
</span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);">&nbsp;com.test.action;<br />
<br />
</span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;com.opensymphony.xwork2.ActionSupport;<br />
<br />
</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;LoginAction&nbsp;</span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);">&nbsp;ActionSupport{&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">此处继承的父类ActionSupport就是struts2的一个典型应用</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);">&nbsp;String&nbsp;username;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);">&nbsp;String&nbsp;password;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;String&nbsp;getUsername()<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;username;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;setUsername(String&nbsp;username)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.username&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;username;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;String&nbsp;getPassword()<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;password;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;setPassword(String&nbsp;password)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.password&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;password;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;String&nbsp;execute()&nbsp;</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);">&nbsp;Exception<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">hello</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.equals(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getUsername().trim())</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">word</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.equals(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getPassword().trim()))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">success</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.addFieldError(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">username</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">username&nbsp;or&nbsp;password&nbsp;error!!!!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">failer</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;validate()&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">验证</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getUsername()</span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">.equals(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getUsername().trim()))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.addFieldError(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">username</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">username&nbsp;request</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getPassword()</span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">.equals(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getPassword().trim()))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.addFieldError(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">password</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">password&nbsp;request</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;<br />
<br />
}<br />
</span></div>
<br />
在webroot下建立如下jsp文件，login2.jsp,result.jsp<br />
<br />
<br />
login2.jsp<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">&lt;%</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">@&nbsp;page&nbsp;language</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">java</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;contentType</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">text/html;&nbsp;charset=ISO-8859-1</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;pageEncoding</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">ISO-8859-1</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">&lt;%</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">@&nbsp;taglib&nbsp;prefix</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">s</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;&nbsp;uri</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">/struts-tags</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;</span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE&nbsp;html&nbsp;PUBLIC&nbsp;"-//W3C//DTD&nbsp;HTML&nbsp;4.01&nbsp;Transitional//EN"&nbsp;"http://www.w3.org/TR/html4/loose.dtd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="Content-Type"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="text/html;&nbsp;charset=ISO-8859-1"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Insert&nbsp;title&nbsp;here</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">s:form&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">action</span><span style="color: rgb(0, 0, 255);">="login"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">s:textfield&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="username"</span><span style="color: rgb(255, 0, 0);">&nbsp;label</span><span style="color: rgb(0, 0, 255);">="username"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">s:textfield</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">s:password&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="password"</span><span style="color: rgb(255, 0, 0);">&nbsp;label</span><span style="color: rgb(0, 0, 255);">="password"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">s:password</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">s:submit&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="submit"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">s:submit</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">s:form</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span></div>
<br />
<br />
<br />
result.jsp<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">&lt;%</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">@&nbsp;page&nbsp;language</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">java</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;import</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">java.util.*</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;pageEncoding</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">ISO-8859-1</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">&lt;%</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);"><br />
</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 255);">String</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;path&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;request.getContextPath();<br />
</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 255);">String</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;basePath&nbsp;</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">&nbsp;request.getScheme()</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">+</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">://</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">+</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">request.getServerName()</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">+</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">:</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">+</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">request.getServerPort()</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">+</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">path</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">+</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">/</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">;<br />
</span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE&nbsp;HTML&nbsp;PUBLIC&nbsp;"-//W3C//DTD&nbsp;HTML&nbsp;4.01&nbsp;Transitional//EN"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">base&nbsp;</span><span style="color: rgb(255, 0, 0);">href</span><span style="color: rgb(0, 0, 255);">="&lt;%=basePath%&gt;"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">My&nbsp;JSP&nbsp;'result.jsp'&nbsp;starting&nbsp;page</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="pragma"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="no-cache"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="cache-control"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="no-cache"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="expires"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="0"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="keywords"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="keyword1,keyword2,keyword3"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta&nbsp;</span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="description"</span><span style="color: rgb(255, 0, 0);">&nbsp;content</span><span style="color: rgb(0, 0, 255);">="This&nbsp;is&nbsp;my&nbsp;page"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;link&nbsp;rel="stylesheet"&nbsp;type="text/css"&nbsp;href="styles.css"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;username:${requestScope.username}</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">br</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;password:${requestScope.password}<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span></div>
<br />
<br />
这样就实现了简单的固定用户登陆，username:hello&nbsp;&nbsp; password:word&nbsp;&nbsp; <br />
<br />
实现界面<br />
<img src="http://www.blogjava.net/images/blogjava_net/yxc0433/2.JPG" alt="" border="0" /><br />
<br />
<br />
<img src="http://www.blogjava.net/images/blogjava_net/yxc0433/3.JPG" alt="" border="0" /><br />
<br />
<br />
<br />
<img src ="http://www.blogjava.net/yxc0433/aggbug/200545.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yxc0433/" target="_blank">yxc</a> 2008-05-15 01:12 <a href="http://www.blogjava.net/yxc0433/archive/2008/05/15/200545.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>