⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jbuilder_struts.htm

📁 用Jbuilder开发Strusts的例子
💻 HTM
📖 第 1 页 / 共 2 页
字号:
  <tr>
    <td width="4%"> </td>
    <td width="87%"><font size="2">public class MyAction extends Action {<br>
&nbsp;&nbsp; public ActionForward execute(ActionMapping parm1, ActionForm parm2,
    <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpServletRequest parm3, 
    HttpServletResponse&nbsp;&nbsp;&nbsp;&nbsp; parm4) throws 
    java.lang.Exception {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyActionForm myActionForm=(MyActionForm)parm2 
    ;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String sA = myActionForm.getStr1 ( ) ;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String sB = myActionForm.getStr2 ( ) ;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myActionForm.setResult (sA+sB) ;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&quot;HelloAction.do 
    executing..........&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ( parm1.findForward ( &quot;hello&quot; ) ) ;<br>
&nbsp;&nbsp; }<br>
    }</font></td>
    <td width="9%"> </td>
  </tr>
</table>

<p><span class="f14"><font size="2"><br>
<br>
 </font><b> 步骤五 : 修改struts-config.xml文件和MyJsp1.jsp<br>
</b><font size="2">
<br>
  从现在开始,基本进入手动修改状态。点击选择 JBuilder 左上方之项目窗格 ( Project Pane ) 内之struts-config.xml,此时集成开发环境便可以图形使用者接口方式编辑 
struts-config.xml 内容,左下方结构窗格( Structure Pane ) 会依照 struts-config.xml 结构,分为 
DataSources 、Form Beans、Global Forwards 与 Action Mappings四类标记项目。<br>
<br>
  <img border="0" src="JBuilder_Structs_img/Struts-ConfigXml1.jpg" width="229" height="300">&nbsp;&nbsp;
<img border="0" src="JBuilder_Structs_img/Struts-ConfigXml2.jpg" width="469" height="297"><br>
&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; 选择Global Forwards,添加一个选项,Name: hello&nbsp;&nbsp; 
Path:/Myjsp1.jsp<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; 单击右下角的Source,修改xml的源代码。修改第2行中的Struts版本号为1.1。具体的xml文件如下:</font></span></p>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
  <tr>
    <td width="7%"> </td>
    <td width="76%" rowspan="2"><font size="2">&lt;?xml version=&quot;1.0&quot; 
    encoding=&quot;UTF-8&quot;?&gt;<br>
    &lt;!DOCTYPE struts-config PUBLIC &quot;-//Apache Software Foundation//DTD Struts 
    Configuration <font color="#FF0000">1.1</font>//EN&quot; &quot;http://jakarta.apache.org/struts/dtds/struts-config_<font color="#FF0000">1_1</font>.dtd&quot;&gt;<br>
    &lt;struts-config&gt;<br>
    &lt;form-beans&gt;<br>
    &lt;form-bean name=&quot;myActionForm&quot; type=&quot;mytest.MyActionForm&quot; /&gt;<br>
    &lt;/form-beans&gt;<br>
    &lt;global-forwards&gt;<br>
    &lt;forward name=&quot;hello&quot; path=&quot;/MyJsp1.jsp&quot; /&gt;<br>
    &lt;/global-forwards&gt;<br>
    &lt;action-mappings&gt;<br>
    &lt;action name=&quot;myActionForm&quot; type=&quot;mytest.MyAction&quot; input=&quot;/MyJsp1.jsp&quot; <b>
    <font color="#0000FF">scope=&quot;request&quot; path=&quot;/MyAction1</font></b>&quot; /&gt;<br>
    &lt;/action-mappings&gt;<br>
    &lt;/struts-config&gt;</font></td>
    <td width="17%"> </td>
  </tr>
  <tr>
    <td width="7%"> </td>
    <td width="17%"> </td>
  </tr>
</table>

<p><span class="f14"><font size="2">&nbsp;&nbsp;&nbsp; 
该XML将为Action类做一个映射,如上用蓝色标明的部分,以后通过 &quot;/MyAction1&quot; 就可以访问 mytest.MyAction这个类。</font></span></p>

<p><span class="f14"><font size="2">&nbsp;&nbsp;&nbsp; 
在MyJsp1.jsp文件的form的action中,使用这个标签。将Form的处理页设置为该类&nbsp; &lt;html:form action=&quot;MyAction.do&quot; 
method=&quot;POST&quot;&gt; ,并且确定在jsp文件中,属性控件str1、str2和result的顺序是 str1,str2,result。 <br>
<br>
  </font></span><font size="2"><br>
 </font><b> 步骤六 : 设定执行组件</b><font size="2"><br>
<br>
  单击工具栏中的 Run Configurationg ,将弹出Run的设置菜单。</font></p>

<p>
<font size="2">
&nbsp;&nbsp;&nbsp;
<img border="0" src="JBuilder_Structs_img/run1.jpg" width="285" height="119"><br>
<img border="0" src="JBuilder_Structs_img/run2.jpg" width="440" height="396">&nbsp;
<img border="0" src="JBuilder_Structs_img/run3.jpg" width="335" height="450"></font></p>

<p><font size="2">&nbsp;&nbsp; 将Type设置为Server,并且选择JSP/Server中的Jsp为MyJsp1.jsp。<br>
<br>
  此时执行组件属性设定对话框中主要项目皆已设定完毕,按下 OK 按钮返回项目属性设定对话框。项目属性对话框中将把前述步骤所设定之执行组件列于Runtime 
Configurations 清单方块中,按下 OK 按钮即完成执行组件设定。<br>
<br>
 </font><b> 步骤七 : 执行 Web 应用程序</b><font size="2"><br>
<br>
  接下来可点击选择 JBuilder 菜单 Run 或工具列中绿色三角形符号执行此 Web 应用程序。JBuilder 将于集成开发环境内激活 Tomcat 
4.0 Server,我们可以通过 JBuilder 内置之 Web 浏览器进行测试。在 Web 浏览器中我们键入 AAA 与 BBB 按下 Submit 按钮,得到预期之运算结果AAABBB。<br>
<br>
<img onerror="this.src='/Article/UploadFiles/200409/20040908132525196.jpg';" hspace="3" src="JBuilder_Structs_img/result.jpg" align="center" vspace="1" border="1" width="283" height="168"><br>
<br>
 </font></p>

<p><font size="2">&nbsp; </font><b>&nbsp;步骤八:设置使之能识别中文文字</b></p>

<p><font size="2">  处理方法是:</font></p>

<p><font size="2">&nbsp;&nbsp;&nbsp; (1)在 JSP 起始处加上:<br>
<br>
<%@ page contentType=&quot;text/html; charset=MS950&quot; %>  对于繁体中文<br>
<br>
<%@ page contentType=&quot;text/html; charset=GB2312&quot; %>&nbsp;&nbsp; 
对于简体中文(常用编码为GB2312)<br>
<br>
<br>
&nbsp;&nbsp;&nbsp; (2)创建一个Serverlet类处理接收字体的编码<br>
<br>
</font>
<span class="f14"><font size="2">  首先,点击选择 JBuilder 主菜单 File | New Classes 准备产生一新的类。并继承自org.apache.struts.action.ActionServlet并将预设的类名称由Untitled1 
改为 myActionServlet。按下 OK 按钮后即产生程序代码。点击选择 JBuilder 主菜单Wizards | Override Methods… 
激活覆盖方法精灵,覆盖方法精灵会自动列出父类 ActionServlet 所有可供覆盖之方法。我们可于 Available methods 
清单方块中选取process (HttpServletRequest request, HttpServletResponse response) 
方法,完成后按下 OK 按钮。<br>
<img border="0" src="JBuilder_Structs_img/process.jpg" width="476" height="349"><br>
&nbsp;&nbsp;&nbsp; 此时我们可修改覆盖后 process 方法程序代码如下:</font></span>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3">
  <tr>
    <td width="7%"> </td>
    <td width="43%">
<span class="f14"><font size="2">
request.setCharacterEncoding (&quot;MS950&quot;) ;<br>
super.process (request, response) ;</font></span></td>
    <td width="32%">
<span class="f14"><font size="2">
request.setCharacterEncoding (&quot;GB2312&quot;) ;<br>
super.process (request, response) ;</font></span></td>
    <td width="18%"> </td>
  </tr>
  <tr>
    <td width="7%"> </td>
    <td width="43%">//繁体中文</td>
    <td width="32%">//简体中文</td>
    <td width="18%"> </td>
  </tr>
</table>

<p>
&nbsp;&nbsp;&nbsp;
<span class="f14"><font size="2">
接下来我们将要修改 web.xml部署描述档,以指定 
Servlet 之进入点,首先点击选择左上方项目窗格中的 web.xml。<br>
<br>
<img onerror="this.src='/Article/UploadFiles/200409/20040908132525267.jpg';" hspace="3" src="JBuilder_Structs_img/webXml.jpg" align="center" vspace="1" border="1" width="214" height="273"><br>
<br>
<br>
  点击选择内容窗格内的 Sources 页次,直接以文字编辑器修改<servlet-class> 标记的内容:&nbsp;&nbsp; &lt;servlet-class&gt;</font></span><font size="2">mytest</font><span class="f14"><font size="2">.myActionServlet&lt;/servlet-class&gt;<br>
<br>
</font></span><font size="2">  完成后重新编译此项目并执行之。再次测试后我们将发现中文已经可以正确处理。</font></p>

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -