struts超簡單入門(二)

來源:互聯網
上載者:User

【hello.jsp】內容:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html:html locale="true"><head>  <title><bean:message key="hello.jsp.title" /></title>  <html:base/></head>

<body>  <p><h2><bean:message key="hello.jsp.page.heading" /></h2></p>  <html:errors /><p>  <logic:present name="helloForm" scope="request">    <h2>Hello <bean:write name="helloForm" property="person" />!</h2>  </logic:present>

  <html:form action="helloWorld.do" focus="person">    <bean:message key="hello.jsp.prompt.person" />    <html:text property="person" size="20" maxlength="20" /><br> <html:submit property="submit" value="提交" /> <html:reset/>  </html:form><br>

  <html:img page="/struts-power.jpg" alt="Powered by Struts" /></body>

</html:html>

【struts-config.xml】內容:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>  <form-beans>    <form-bean name="helloForm" type="com.javer.test.struts.HelloFrom"/>  </form-beans>

  <action-mappings>    <action path="/helloWorld" type="com.javer.test.struts.HelloAction" name="helloForm" scope="request" validate="true" input="/hello.jsp">   <forward name="SayHello" path="/hello.jsp" /> </action>  </action-mappings>

  <message-resources parameter="com.javer.test.struts.Application" /></struts-config>

【web.xml】內容:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>  <filter>    <filter-name>The Webapp Framework Set Character Encoding</filter-name> <filter-class>com.javer.test.struts.EncodingFilter</filter-class> <init-param>   <param-name>encoding</param-name>   <param-value>UTF-8</param-value> </init-param>  </filter>  <filter-mapping>    <filter-name>The Webapp Framework Set Character Encoding</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapping>

  <servlet>    <servlet-name>action</servlet-name>    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>    <init-param>      <param-name>config</param-name>      <param-value>/WEB-INF/struts-config.xml</param-value>    </init-param>    <load-on-startup>2</load-on-startup>  </servlet>

  <servlet-mapping>    <servlet-name>action</servlet-name>    <url-pattern>*.do</url-pattern>  </servlet-mapping>

  <taglib>    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>    <taglib-location>/WEB-INF/lib/struts-bean.tld</taglib-location>  </taglib>  <taglib>    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>    <taglib-location>/WEB-INF/lib/struts-html.tld</taglib-location>  </taglib>  <taglib>    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>    <taglib-location>/WEB-INF/lib/struts-logic.tld</taglib-location>  </taglib></web-app>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.