锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
緇忓父鐪嬭jsp鐗堥噷鏈変漢闂椂闂存搷浣滅殑闂錛岃繖浜涢棶棰樹竴鑸寘鎷細鍙栧綋鍓嶆椂闂達紝鎶婁竴涓寚瀹氱殑瀛楃涓叉椂闂磋漿鍖栨垚鏃墮棿綾誨瀷錛屾眰涓や釜鏃墮棿涔嬮棿鐨勫ぉ鏁幫紝姹備竴孌墊椂闂翠互鍓嶇殑鏃墮棿錛屾眰涓孌墊椂闂翠互鍚庣殑鏃墮棿錛屽湪榪欓噷灝辨妸榪欎簺闂姹囨諱竴涓嬨?br /><%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<%
//瀛楃涓茶漿鍖栨垚鏃墮棿綾誨瀷錛堝瓧絎︿覆鍙互鏄換鎰忕被鍨嬶紝鍙鍜孲impleDateFormat涓殑鏍煎紡涓鑷村嵆鍙級
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("M/dd/yyyy hh:mm:ss a",java.util.Locale.US);
java.util.Date d = sdf.parse("5/13/2003 10:31:37 AM");
out.println(d);
out.println("<br>");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mDateTime1=formatter.format(d);
out.println(mDateTime1);
out.println("<br>");
out.println(d.getTime());
out.println("<br>");
//褰撳墠鏃墮棿
Calendar cal = Calendar.getInstance();
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss G E D F w W a E F");
String mDateTime=formatter.format(cal.getTime());
out.println(mDateTime);
out.println("<br>");
//1騫村墠鏃ユ湡
java.util.Date myDate=new java.util.Date();
long myTime=(myDate.getTime()/1000)-60*60*24*365;
myDate.setTime(myTime*1000);
String mDate=formatter.format(myDate);
out.println(mDate);
out.println("<br>");
//鏄庡ぉ鏃ユ湡
myDate=new java.util.Date();
myTime=(myDate.getTime()/1000)+60*60*24;
myDate.setTime(myTime*1000);
mDate=formatter.format(myDate);
out.println(mDate);
out.println("<br>");
//涓や釜鏃墮棿涔嬮棿鐨勫ぉ鏁?br />SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date date= myFormatter.parse("2003-05-1");
java.util.Date mydate= myFormatter.parse("1899-12-30");
long day=(date.getTime()-mydate.getTime())/(24*60*60*1000);
out.println(day);
out.println("<br>");
//鍔犲崐灝忔椂
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
java.util.Date date1 = format.parse("2002-02-28 23:16:00");
long Time=(date1.getTime()/1000)+60*30;
date1.setTime(Time*1000);
String mydate1=formatter.format(date1);
out.println(mydate1);
out.println("<br>");
//騫存湀鍛ㄦ眰鏃ユ湡
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM F E");
java.util.Date date2= formatter2.parse("2003-05 5 鏄熸湡浜?);
SimpleDateFormat formatter3 = new SimpleDateFormat("yyyy-MM-dd");
String mydate2=formatter3.format(date2);
out.println(mydate2);
out.println("<br>");
//姹傛槸鏄熸湡鍑?br />mydate= myFormatter.parse("2001-1-1");
SimpleDateFormat formatter4 = new SimpleDateFormat("E");
String mydate3=formatter4.format(mydate);
out.println(mydate3);
out.println("<br>");
%>
鍘熸潵鎬鐤戜笌xml欏甸潰鐨勭紪鐮佹湁鍏寵瘯浜嗕竴涓嬶紝濂藉儚涓嶈搗浣滅敤銆?br />
榪欎釜闂璁╂垜閮侀椃浜嗕袱涓夊ぉ鏃墮棿,鏈鍚庢墠鍙戠幇闂鏄湪JSP绔?<html:form action="/uploadsAction"聽 enctype="multipart/form-data"聽 >
鏍囩濡傛灉灝戜簡"聽 enctype="multipart/form-data" 聽鏈嶅姟鍣ㄥ氨浼氭姤閿?
涓嬮潰鎶婁唬鐮佽創(chuàng)鍑烘潵.
JSP绔?br />聽<html:errors />
聽聽聽聽聽聽聽聽聽 <html:form action="/uploadsAction"聽 enctype="multipart/form-data"聽 >
聽聽聽聽聽聽聽聽聽聽聽 <html:file property="theFile" />聽
聽聽聽聽聽聽聽聽聽聽聽聽 <html:radio property="upType" value="a" />CSVFileReader
聽聽聽聽聽聽聽聽聽聽聽聽 <html:radio property="upType" value="b" />FileUp聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 <html:submit value="OK"聽 />
聽聽聽聽聽聽聽聽聽 </html:form>
FormBean涓皢灞炴у畾涔変負FormFile,geter seter 鏂規(guī)硶渚濇棫.
Action 涓殑浠g爜濡備笅:瀹炵幇灝嗗浘鐗囦笂浼犺嚦UPLOAD鏂囦歡澶瑰唴 濡傛灉鏂囦歡澶т簬20K鎴栨槸瀹斤紗楂樿秴榪囪瀹氳寖鍥寸殑,浼氶噸鏂板嬀鐢?瀹炵幇瀵逛笂浼犲浘鐗囩殑鎺у埗.
褰撶劧榪欏彧鏄祴璇旳ction娌℃湁璺寵漿欏甸潰..
package upload;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import org.apache.struts.upload.*;
import java.io.IOException;
import java.awt.Image;
import java.awt.image.BufferedImage;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.image.codec.jpeg.JPEGCodec;
import java.io.File;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
public class UploadAction extends Action {
聽聽聽 public ActionForward execute(ActionMapping actionMapping,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ActionForm actionForm,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 HttpServletRequest servletRequest,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 HttpServletResponse servletResponse)throws Exception {
聽聽聽聽聽聽聽 System.out.println("asdasdasdasdasdasd");
聽聽聽聽聽聽聽 UploadForm uploadForm = (UploadForm) actionForm;
聽聽聽聽聽聽聽 FormFile pic =聽 uploadForm.getPic();
聽聽聽聽聽聽聽 String picname = pic.getFileName();
聽聽聽聽聽聽聽 String uploadFileName = servletRequest.getSession()
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 .getServletContext()
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 .getRealPath("upload")+"\\"+picname;
聽聽聽聽聽聽聽 File upliadFile = new File(uploadFileName);
聽聽聽聽聽聽聽 BufferedInputStream bis = null;
聽聽聽聽聽聽聽 Image image = null;
聽聽聽聽聽聽聽 BufferedOutputStream bos = null;
聽聽聽聽聽聽聽 try{
聽聽聽聽聽聽聽 if(pic.getFileSize()<2*1024*1024){
聽聽聽聽聽聽聽 bis = new BufferedInputStream(pic.getInputStream());
聽聽聽聽聽聽聽 image = javax.imageio.ImageIO.read(bis);
聽聽聽聽聽聽聽 int width = image.getWidth(null);
聽聽聽聽聽聽聽 int height = image.getHeight(null);
聽聽聽聽聽聽聽 int w = 160;
聽聽聽聽聽聽聽 int h = 120;
聽聽聽聽聽聽聽 if(width>w||height>h){
聽聽聽聽聽聽聽 BufferedImage bi = new BufferedImage(w,h,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 BufferedImage.TYPE_INT_RGB);
聽聽聽聽聽聽聽 bi.getGraphics().drawImage(image,0,0,w,h,null);
聽聽聽聽聽聽聽 bos = new BufferedOutputStream(new FileOutputStream(
聽聽聽聽聽聽聽upliadFile));
聽聽聽聽聽聽聽 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
聽聽聽聽聽encoder.encode(bi);
聽聽聽聽聽聽聽 System.out.println(width * height);
聽聽聽聽聽聽聽 }else{
聽聽聽聽聽聽聽 bos = new BufferedOutputStream(new FileOutputStream(upliadFile));
聽聽聽聽聽聽聽 byte[] date = new byte[5*1024];
聽聽聽聽聽聽聽 int len = bis.read(date);
聽聽聽聽聽聽聽 while (len!=-1){
聽聽聽聽聽聽聽聽聽聽聽 bos.write(date);
聽聽聽聽聽聽聽聽聽聽聽 len = bis.read(date);
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽 return actionMapping.findForward("ok");
聽聽聽聽聽聽聽 }catch(Exception e){
聽聽聽聽聽聽聽 e.printStackTrace();
聽聽聽 } finally {
聽聽聽聽聽聽聽 try {
聽聽聽聽聽聽聽聽聽聽聽 if (bis != null)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 bis.close();
聽聽聽聽聽聽聽 } catch (IOException e1) {
聽聽聽聽聽聽聽聽聽聽聽 e1.printStackTrace();
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 try {
聽聽聽聽聽聽聽聽聽聽聽 if (bos != null)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 bos.close();
聽聽聽聽聽聽聽 } catch (IOException e2) {
聽聽聽聽聽聽聽聽聽聽聽 e2.printStackTrace();
聽聽聽聽聽聽聽 }
聽聽聽 }
聽聽聽聽聽聽聽 return actionMapping.findForward("ok");
聽聽聽 }
}
閰嶇疆榪囩▼錛?/p>
涓銆佷笅杞藉繀瑕佺殑jar鍖呫傛湁鍥涗釜鍖呰涓嬭澆錛堢綉涓婃湁璐村瓙璇村彧瑕佷笅闈㈠墠涓変釜鍖呭氨鍙互浜嗭紝浣嗘垜鍦ㄩ厤緗殑鏃跺欏鏋滄病鏈夌鍥涗釜鍖呬細鎶ラ敊錛夈?br />http://apache.linuxforum.net/dist/jakarta/commons/dbcp/binaries/commons-dbcp-1.2.zip
http://apache.linuxforum.net/dist/jakarta/commons/pool/binaries/commons-pool-1.2.zip
http://apache.linuxforum.net/dist/jakarta/struts/struts-legacy/struts-legacy-1.0.zip
http://apache.linuxforum.net/dist/jakarta/commons/collections/binaries/commons-collections-3.1.zip
鎶婅繖鍥涗釜jar鍖呮斁鍒皐eb搴旂敤鐨刉EB-INF/lib鐩綍涓嬶紝榪樻湁瑕佹妸MySQL鐨勯┍鍔ㄧ▼搴忓寘涔熸斁鍒拌繖閲岋紙涔熷彲浠ユ妸鏁版嵁搴撶殑椹卞姩鍖呮斁鍒?Tomcat_Home%/common/lib鐩綍涓嬫垨%Resin_Home%/lib鐩綍涓嬶紝榪欐牱鍦ㄥ惎鍔╓eb鏈嶅姟鍣ㄧ殑鏃跺欏氨浼氬姞杞借繖涓寘錛屾湇鍔″櫒鍜學eb搴旂敤閮藉彲浠ヤ嬌鐢ㄩ┍鍔ㄧ▼搴忕被錛?/p>
浜屻佸湪struts-config.xml涓坊鍔燚ata Source銆侻yEclipse鐨凞esign妯″紡涓嬪彲浠ュ彲瑙嗗寲鍦扮紪杈憇truts-config.xml鍜屾坊鍔燚ata Source錛屼絾瀹冨湪struts-config.xml涓敓鎴愮殑鏁版嵁婧愮殑浠g爜鏄敊璇殑錛佸氨鏄洜涓鴻繖涓借浜嗘垜寰堝鏃墮棿錛?br />鎴戜滑鎵嬪伐緙栬緫浠g爜錛?/p>
<data-sources>
<data-source key="datasource" type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="password" value="admin" />
<set-property property="minCount" value="3" />
<set-property property="maxCount" value="10" />
<set-property property="username" value="admin" />
<set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
<set-property property="description" value="test" />
<set-property property="url" value="jdbc:mysql://localhost/test" />
<set-property property="readOnly" value="false" />
<set-property property="autoCommit" value="true" />
</data-source>
</data-sources>
濡傛灉瑕侀厤緗涓猟ata source錛屽彲浠ョ粰姣忎釜data source鎸囧畾涓嶅悓鐨刱ey錛岀劧鍚庡湪紼嬪簭涓牴鎹甼ey鎸囧畾瑕佸紩鐢ㄧ殑鏁版嵁婧愩?/p>
涓夈佹祴璇曟暟鎹簮銆傞厤緗ソ浠ュ悗灝卞彲浠ュ湪ActionServlet涓嬌鐢ㄤ簡銆?/p>
DataSource ds = getDataSource(request,"datasource");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SQL String");
闄勶細 Struts1.1涓璼truts-config.xml鐨勯厤緗細
<data-sources >
<data-source key="datasource" type="org.apache.struts.util.GenericDataSource">
<set-property property="password" value="admin" />
<set-property property="minCount" value="2" />
<set-property property="maxCount" value="10" />
<set-property property="user" value="admin" />
<set-property property="driverClass" value="com.mysql.jdbc.Driver" />
<set-property property="description" value="test" />
<set-property property="url" value="jdbc:mysql://localhost/test" />
<set-property property="readOnly" value="false" />
<set-property property="autoCommit" value="true" />
</data-source>
</data-sources>
娉ㄦ剰錛氳摑鑹插瓧浣撶殑閮ㄥ垎鏄?.1鍜?.2鍦ㄩ厤緗笂涓嶄竴鏍風殑鍦版柟銆?br />
<!DOCTYPE struts-config PUBLIC
聽</data-sources> 聽 <action-mappings> 聽 <controller> 浜屻丄ction綾? package page; import java.util.*; public class DataSourceAction extends Action { 聽public DataSourceAction(){} 聽聽聽聽聽聽聽 // if there is a previous page, set the previous variable聽 聽聽聽聽聽聽聽 // if there is a next page, set the next variable聽 聽聽 }catch(SQLException e){
public int getId(){聽 聽public String getAuthor() { 聽public void setAuthor(String author) { 聽public String getBookname() { 聽public void setBookname(String bookname) { <logic:iterate id="book" name="list" type="bean.Book">聽 <form action="/TestPage/page.do"> 聽聽 <logic:present name="next">聽 姣忛〉<c:out value="${page}"/>鏉¤褰?鍏?lt;c:out value="${pages}"/>欏德?璺沖埌<input type="text"聽 name="go" size="3" maxlength="30" > 聽 OK!!!!
聽聽聽聽聽聽聽聽聽 "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
聽聽聽聽聽聽聽聽聽 "
<struts-config>
<data-sources>
聽聽 <data-source key="dataSource" type="org.apache.commons.dbcp.BasicDataSource">
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="url" value="jdbc:odbc:page" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="username" value="admin" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="password" value="" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="maxActive" value="20" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="maxWait" value="5000" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="defaultAutoCommit" value="true" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="defaultReadOnly" value="false" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="validationQuery" value="SELECT 1" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="removeAbandoned" value="true" />
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="removeAbandonedTimeout" value="120" />聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 <set-property property="encoding" value="false" />聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 </data-source>
聽 <form-beans>
聽 </form-beans>
聽 <global-forwards>
聽 </global-forwards>
聽 <action path="/page" type="page.DataSourceAction" scope="request">
聽 <forward name="success" path="/pagetest.jsp"/>
聽 </action>
聽 </action-mappings>
聽 </controller>
</struts-config>
鐢?page.do?start=1 鏉ユ樉紺虹涓涓〉闈⒙?
鍙傛暟璇存槑錛毬?
聽 list錛氫俊鎭垪琛?
聽 start錛氬紑濮嬩綅緗?
聽 page錛氭瘡欏墊樉紺虹殑淇℃伅鏁扮洰聽
聽 pages: 鎬婚〉鏁?
聽 previous錛氫笂欏靛紑濮嬩綅緗?
聽 next錛氫笅欏靛紑濮嬩綅緗?
import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
import bean.*;
聽
聽public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
聽HttpServletResponse response) throws Exception {聽聽聽
聽 try{
聽聽聽聽聽 DataSource ds=this.getDataSource(request,"dataSource");聽聽聽
聽聽聽聽聽 Connection con = ds.getConnection();
聽聽聽聽聽 Statement stmt = con.createStatement();
聽聽聽聽聽 ResultSet resultSet = stmt.executeQuery("select count(*) from book" );聽
聽聽聽聽聽 resultSet.next();聽
聽聽聽聽聽 int data_num=resultSet.getInt(1);聽
聽聽聽聽聽 int start=1;
聽聽聽聽聽 int page = 4; //姣忛〉鐨勮褰曟暟銆?
聽聽聽聽聽 int pages=data_num/page;
聽聽聽聽聽 if(data_num%page!=0)
聽聽聽聽聽聽聽聽 pages++;
聽聽聽聽聽 if(request.getParameter("start")!=null)
聽聽聽聽聽聽聽聽聽 start = Integer.parseInt(request.getParameter("start"));聽
聽聽聽聽聽 if(request.getParameter("go")!=null){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 int go = Integer.parseInt(request.getParameter("go"));聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 if(go<=1)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 start=1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 else if(go>pages)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 start=(pages-1)*page+1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 else聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 start=(go-1)*page+1;
聽聽聽聽聽聽 }聽
聽聽聽聽聽
聽聽聽聽聽 String sql = "SELECT * FROM book where id>="+start+" and id<"+(start+page);
聽聽聽聽聽 resultSet = stmt.executeQuery(sql);聽聽
聽聽聽聽聽 ArrayList list = new java.util.ArrayList();聽
聽聽聽聽聽 while(resultSet.next())
聽聽聽聽聽 {聽聽
聽聽聽聽聽聽聽 int id=resultSet.getInt("id");
聽聽聽聽聽聽聽 String name = resultSet.getString("name");
聽聽聽聽聽聽聽 String author = resultSet.getString("author");
聽聽聽聽聽聽聽 String price = resultSet.getString("price");
聽聽聽聽聽聽聽 System.out.println("寮濮嬫暟鎹皝瑁咃細name="+name+"author="+author+"price="+price);
聽聽聽聽聽聽聽 Book book= new Book(id,name,author,price);聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 list.add(book);
聽聽聽聽聽 }
聽聽聽 con.close();
聽聽聽 request.setAttribute("pages",new Integer(pages));
聽聽聽 request.setAttribute("list",list);
聽聽聽 //request.setAttribute("start", new Integer(start));聽
聽聽聽 request.setAttribute("page", new Integer(page));聽
聽聽聽聽聽聽聽 int previous = start-page;聽
聽聽聽聽聽聽聽 if ( previous>=0 ){聽
聽聽聽聽聽聽聽聽聽聽聽 request.setAttribute("previous", new Integer(previous));聽
聽聽聽聽聽聽聽聽聽聽聽 System.out.println ("previous:" + previous);聽
聽聽聽聽聽聽聽 }聽
聽聽聽聽聽聽聽 int next = start+page;聽
聽聽聽聽聽聽聽 if ( next<=data_num ){聽
聽聽聽聽聽聽聽聽聽聽聽 request.setAttribute("next", new Integer(next));聽
聽聽聽聽聽聽聽聽聽聽聽 System.out.println ("next:" + next);聽
聽聽聽聽聽聽聽 }聽
聽聽聽聽聽聽聽聽聽 e.printStackTrace();
聽聽聽聽聽聽聽聽聽 System.out.println("鏁版嵁搴撹繛鎺ュ嚭鐜板紓甯?);
聽聽聽聽聽 }聽
聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽 return (mapping.findForward("success"));
聽 }聽
}
涓夈乥ean綾籅ook.java
package bean;
import java.sql.*;
import java.util.ArrayList;
public class Book {
聽int id;
聽private String bookname; //涔﹀悕
聽private String author;聽聽 //浣滆?
聽private String price;聽聽聽 //浠鋒牸
聽
public Book(int id,String name,String author,String price){
聽this.id=id;
聽this.bookname=name;
聽this.author=author;
聽this.price=price;
}
聽聽聽聽聽聽聽 return id;聽
聽聽聽 }聽
聽 return author;
聽}
聽 this.author = author;
聽}
聽 return bookname;
聽}
聽 this.bookname = bookname;
聽}
聽
聽public String getPrice(){
聽聽聽聽 return this.price;聽
聽}
聽
聽public void setPrice(String price){
聽聽聽聽 this.price=price;聽
聽}
聽
}
鍥涖佸垎欏電殑jsp欏甸潰pagetest.jsp,鐢ㄤ簡jstl涓殑c鏍囪銆?
<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ page import="java.util.*" %>
<%@ page import="bean.*" %>
<%@ taglib prefix="c" uri="<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
聽聽聽聽聽聽聽聽聽聽聽 <br><html:link聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 paramId="id" paramName="book" paramProperty="id"聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 page="/messagedetail.do">聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <bean:write name="book" property="bookname" />聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </html:link>聽
</logic:iterate>聽
聽聽 <logic:present name="previous">聽
聽聽聽聽聽聽聽聽聽聽聽 <html:link聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 paramId="start" paramName="previous"聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 page="/page.do">聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 涓婁竴欏德?
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </html:link>聽
聽聽 </logic:present>聽
聽聽聽聽聽聽聽聽聽聽聽聽聽 <html:link聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 paramId="start" paramName="next"聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 page="/page.do">聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 涓嬩竴欏德?
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </html:link>聽
聽聽 </logic:present>聽
<input type="submit" value="go" >
</form>
聽聽聽聽聽聽聽聽聽
浜斻佹祴璇曪紝璇蜂笅杞芥湰瀹炰緥鐨勭洰褰曠粨鏋凾estPage,鏀懼叆tomcat鐨剋ebapps涓嬶紝鍦ㄦ祻瑙堝櫒涓緭鍏ワ細
聽聽聽 http://127.0.0.1:8080/TestPage/page.do聽
鏉ユ簮錛?java瀛︿範瀹?br />聽
]]>
涓銆佸湪struts涓垎欏墊湁涓ょ緇撴瀯錛?
聽聽聽 1. 鍦ˋction涓氳繃DAO鏌ヨ鍑烘墍鏈夌殑璁板綍錛岀劧鍚庡姞鍒皊ession鎴杛equest瀵硅薄涓紝浼犲埌瀹㈡埛绔紝鐢盝SP榪涜鍒嗛〉銆傝繖縐嶆柟娉曞浜庡湪鏁版嵁閲忓皯鐨勬椂鍊欏緢鏂逛究錛屼篃涓嶅獎鍝嶉熷害銆?
聽聽聽 2.鍦ˋction涓瘡嬈¢氳繃DAO鍙煡璇㈠嚭涓欏電殑璁板綍錛屽啀浼犵粰JSP欏甸潰銆傝繖縐嶇粨鏋勫浜庢暟鎹噺澶х殑紼嬪簭寰堝ソ錛屼絾瀵逛簬鏁版嵁閲忓皬鐨勬儏鍐碉紝浼氬鍔犲鏈嶅姟鍣ㄧ殑璇鋒眰錛屽姞澶ф湇鍔″櫒鐨勮礋杞姐?
聽聽聽聽聽
浜屻丠ibernate鏌ヨ
聽聽聽 鐢變簬鍦℉ibernate涓洿鎺ユ彁渚涗簡瀵規(guī)暟鎹簱瀹氱偣瀹氶噺鐨勬煡璇㈡柟娉曪紝鎵浠ユ垜閲囩敤鐨勬槸絎?縐嶆柟娉曘?
濡傦細
浠庣1涓囨潯寮濮嬪彇鍑?00鏉¤褰?
Query q = session.createQuery("from Cat as c");
q.setFirstResult(10000);
q.setMaxResults(100);
List l = q.list();
涓夈佸叿浣撳疄鐜?
聽1.Pager綾?
package com.jpcf.db.helper;
import java.math.*;
public class Pager {
聽 private int totalRows; //鎬昏鏁?
聽 private int pageSize = 10; //姣忛〉鏄劇ず鐨勮鏁?
聽 private int currentPage; //褰撳墠欏靛彿
聽 private int totalPages; //鎬婚〉鏁?
聽 private int startRow; //褰撳墠欏靛湪鏁版嵁搴撲腑鐨勮搗濮嬭
聽 public Pager() {
聽 }
聽 public Pager(int _totalRows) {
聽聽聽 totalRows = _totalRows;
聽聽聽 totalPages=totalRows/pageSize;
聽聽聽 int mod=totalRows%pageSize;
聽聽聽 if(mod>0){
聽聽聽聽聽 totalPages++;
聽聽聽 }
聽聽聽 currentPage = 1;
聽聽聽 startRow = 0;
聽 }
聽 public int getStartRow() {
聽聽聽 return startRow;
聽 }
聽 public int getTotalPages() {
聽聽聽 return totalPages;
聽 }
聽 public int getCurrentPage() {
聽聽聽 return currentPage;
聽 }
聽 public int getPageSize() {
聽聽聽 return pageSize;
聽 }
聽 public void setTotalRows(int totalRows) {
聽聽聽 this.totalRows = totalRows;
聽 }
聽 public void setStartRow(int startRow) {
聽聽聽 this.startRow = startRow;
聽 }
聽 public void setTotalPages(int totalPages) {
聽聽聽 this.totalPages = totalPages;
聽 }
聽 public void setCurrentPage(int currentPage) {
聽聽聽 this.currentPage = currentPage;
聽 }
聽 public void setPageSize(int pageSize) {
聽聽聽 this.pageSize = pageSize;
聽 }
聽 public int getTotalRows() {
聽聽聽 return totalRows;
聽 }
聽 public void first() {
聽聽聽 currentPage = 1;
聽聽聽 startRow = 0;
聽 }
聽 public void previous() {
聽聽聽 if (currentPage == 1) {
聽聽聽聽聽 return;
聽聽聽 }
聽聽聽 currentPage--;
聽聽聽 startRow = (currentPage - 1) * pageSize;
聽 }
聽 public void next() {
聽聽聽 if (currentPage < totalPages) {
聽聽聽聽聽 currentPage++;
聽聽聽 }
聽聽聽 startRow = (currentPage - 1) * pageSize;
聽 }
聽 public void last() {
聽聽聽 currentPage = totalPages;
聽聽聽 startRow = (currentPage - 1) * pageSize;
聽 }
聽 public void refresh(int _currentPage) {
聽聽聽 currentPage = _currentPage;
聽聽聽 if (currentPage > totalPages) {
聽聽聽聽聽 last();
聽聽聽 }
聽 }
}
Pager綾葷敤浜庤綆楅欏點佸墠涓欏點佷笅涓欏點佸熬欏電殑鍦ㄦ暟鎹簱涓殑璧峰琛岋紝褰撳墠鐨勯〉鐮併?
2.PagerHelp綾?
package com.jpcf.db.helper;
import javax.servlet.http.*;
public class PagerHelper {
聽 public static Pager getPager(HttpServletRequest httpServletRequest,int totalRows) {
聽聽聽 //瀹氫箟pager瀵硅薄錛岀敤浜庝紶鍒伴〉闈?
聽聽聽 Pager pager = new Pager(totalRows);
聽聽聽 //浠嶳equest瀵硅薄涓幏鍙栧綋鍓嶉〉鍙?
聽聽聽 String currentPage = httpServletRequest.getParameter("currentPage");
聽聽聽 //濡傛灉褰撳墠欏靛彿涓虹┖錛岃〃紺轟負棣栨鏌ヨ璇ラ〉
聽聽聽 //濡傛灉涓嶄負絀猴紝鍒欏埛鏂皃ager瀵硅薄錛岃緭鍏ュ綋鍓嶉〉鍙風瓑淇℃伅
聽聽聽 if (currentPage != null) {
聽聽聽聽聽 pager.refresh(Integer.parseInt(currentPage));
聽聽聽 }
聽聽聽 //鑾峰彇褰撳墠鎵ц鐨勬柟娉曪紝棣栭〉錛屽墠涓欏碉紝鍚庝竴欏碉紝灝鵑〉銆?
聽聽聽 String pagerMethod = httpServletRequest.getParameter("pageMethod");
聽聽聽 if (pagerMethod != null) {
聽聽聽聽聽 if (pagerMethod.equals("first")) {
聽聽聽聽聽聽聽 pager.first();
聽聽聽聽聽 } else if (pagerMethod.equals("previous")) {
聽聽聽聽聽聽聽 pager.previous();
聽聽聽聽聽 } else if (pagerMethod.equals("next")) {
聽聽聽聽聽聽聽 pager.next();
聽聽聽聽聽 } else if (pagerMethod.equals("last")) {
聽聽聽聽聽聽聽 pager.last();
聽聽聽聽聽 }
聽聽聽 }
聽聽聽 return pager;
聽 }
}
PageHelper榪欎釜綾伙紝鎴戜笉鐢ㄨ搴旇涔熺煡閬撶敤鏉ュ共鍢涗簡
3.DAO綾?
package com.jpcf.db.dao;
import com.jpcf.db.model.*;
import com.jpcf.db.helper.HibernateUtil;
import net.sf.hibernate.*;
import java.util.*;
import com.jpcf.db.controller.*;
public class VehiclePropertyDAO {
聽 public Collection findWithPage(int pageSize, int startRow) throws HibernateException {
聽聽聽 Collection vehicleList = null;
聽聽聽 Transaction tx = null;
聽聽聽 try {
聽聽聽聽聽 Session session = HibernateUtil.currentSession();
聽聽聽聽聽 tx = session.beginTransaction();
聽聽聽聽聽 Query q = session.createQuery("from VehicleProperty vp");
聽聽聽聽聽 q.setFirstResult(startRow);
聽聽聽聽聽 q.setMaxResults(pageSize);
聽聽聽聽聽 vehicleList = q.list();
聽聽聽聽聽 tx.commit();
聽聽聽 } catch (HibernateException he) {
聽聽聽聽聽 if (tx != null) {
聽聽聽聽聽聽聽 tx.rollback();
聽聽聽聽聽 }
聽聽聽聽聽 throw he;
聽聽聽 } finally {
聽聽聽聽聽 HibernateUtil.closeSession();
聽聽聽 }
聽聽聽 return vehicleList;
聽 }
聽 public int getRows(String query) throws HibernateException {
聽聽聽 int totalRows = 0;
聽聽聽 Transaction tx = null;
聽聽聽 try {
聽聽聽聽聽 Session session = HibernateUtil.currentSession();
聽聽聽聽聽 tx = session.beginTransaction();
聽聽聽聽聽 totalRows = ((Integer) session.iterate(query).next()).intValue();
聽聽聽聽聽 tx.commit();
聽聽聽 } catch (HibernateException he) {
聽聽聽聽聽 if (tx != null) {
聽聽聽聽聽聽聽 tx.rollback();
聽聽聽聽聽 }
聽聽聽聽聽 throw he;
聽聽聽 } finally {
聽聽聽聽聽 HibernateUtil.closeSession();
聽聽聽 }
聽聽聽 return totalRows;
聽 }
}
DAO綾繪垜灝辮創(chuàng)榪欎簺鍒嗛〉闇瑕佺殑浠g爜浜嗐?
鈥渇rom VehicleProperty vp鈥濅篃鍙互鐢ㄤ竴涓弬鏁頒紶榪涙潵錛屾湁鍏磋叮鐨勮嚜宸辨敼涓涓嬪惂
4.Action
涓嬮潰鏄湪Action涓敤鍒扮殑浠g爜錛?
聽 public ActionForward execute(ActionMapping actionMapping,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ActionForm actionForm,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 HttpServletRequest httpServletRequest,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 HttpServletResponse httpServletresponse) {
聽聽聽聽 Collection clInfos = null;//鐢ㄤ簬杈撳嚭鍒伴〉闈㈢殑璁板綍闆嗗悎
聽聽聽聽 int totalRows;//璁板綍鎬昏鏁?
聽聽聽聽 VehiclePropertyDAO vehicleDAO = new VehiclePropertyDAO();
聽聽聽 //鍙栧緱褰撳墠琛ㄤ腑鐨勬昏鏁?
聽聽聽 try {
聽聽聽聽聽 totalRows = vehicleDAO.getRows("select count(*) from VehicleProperty");
聽聽聽 } catch (Exception ex) {
聽聽聽聽聽 servlet.log(ex.toString());
聽聽聽聽聽 return actionMapping.findForward(Constants.FAILURE);
聽聽聽 }
聽聽聽 //閫氳繃PagerHelper綾繪潵鑾峰彇鐢ㄤ簬杈撳嚭鍒伴〉闈㈢殑pager瀵硅薄
聽聽聽 Pager pager=PagerHelper.getPager(httpServletRequest,totalRows);
聽聽聽 //鍙栧嚭浠巗tartRow寮濮嬬殑pageSize琛岃褰?
聽聽聽 try {
聽聽聽聽聽 clInfos = vehicleDAO.findWithPage(pager.getPageSize(), pager.getStartRow());
聽聽聽 } catch (Exception ex) {
聽聽聽聽聽 servlet.log(ex.toString());
聽聽聽聽聽 return actionMapping.findForward(Constants.FAILURE);
聽聽聽 }
聽聽聽 //鎶婅緭鍑虹殑璁板綍闆嗗拰pager瀵硅薄淇濆瓨鍒皉equest瀵硅薄涓?
聽聽聽 httpServletRequest.setAttribute("CLINFOS", clInfos);
聽聽聽 httpServletRequest.setAttribute("PAGER", pager);
聽聽聽 return actionMapping.findForward(Constants.SUCCESS);
聽 }
聽聽 鏌ヨ璇彞select count(*) from VehicleProperty 涔熷彲浠ユ崲鎴愪綘闇瑕佺殑浠繪剰鐨勬潯浠訛紙select count(*)聽
from VehicleProperty where ..)
5.JSP欏甸潰浣跨敤
涓嬮潰灝辨槸鍦↗SP涓殑搴旂敤浜嗭細
<td colspan="8" align="right" class="head">
聽聽 絎?lt;bean:write name="PAGER" property="currentPage"/>欏德?
聽聽 鍏?lt;bean:write name="PAGER" property="totalPages"/>欏德?
聽聽 <html:link action="/bussiness/clInfo/queryWithPage.do?method=queryWithPage&pageMethod=first"聽
paramName="PAGER" paramProperty="currentPage" paramId="currentPage">棣栭〉</html:link>
聽聽 <html:link action="/bussiness/clInfo/queryWithPage.do?method=queryWithPage&pageMethod=previous"聽
paramName="PAGER" paramProperty="currentPage" paramId="currentPage">涓婁竴欏?lt;/html:link>
聽聽 <html:link action="/bussiness/clInfo/queryWithPage.do?method=queryWithPage&pageMethod=next"聽
paramName="PAGER" paramProperty="currentPage" paramId="currentPage">涓嬩竴欏?lt;/html:link>
聽聽 <html:link action="/bussiness/clInfo/queryWithPage.do?method=queryWithPage&pageMethod=last"聽
paramName="PAGER" paramProperty="currentPage" paramId="currentPage">灝鵑〉</html:link>
</td>
聽聽 瑙i噴涓涓嬭繖涓琛?"/bussiness/clInfo/queryWithPage.do?method=queryWithPage&pageMethod=first
method=queryWithPage 鏄敱浜庢垜鐨凙ction緇ф壙鐨勬槸DispatchAction,闇瑕佷竴涓猰ethod鍙傛暟
pageMethod=first 鏄敤鏉ュ湪PageHelper綾諱腑鍒ゆ柇鎵ц鍝釜鎿嶄綔
鍥涖佹葷粨
聽聽聽 鎴戝仛鐨勮繖涓篃鍙槸涓涓熼壌錛岃繕鏈夊緢澶氭病鏈夊疄鐜扮殑錛屾瘮濡傝繕鍙互鍔犱竴涓?go 鐩存帴鍒扮n欏電殑鍔熻兘銆?
聽聽聽 鍏跺疄鏈鍏抽敭鐨勬槸鎶婂綋鍓嶉〉鍙峰拰瑕佹墽琛岀殑鏄姛鑳?涓婁竴欏碉紝涓嬩竴欏?鐨勫弬鏁頒粠欏甸潰浼犺繘鏉ワ紝鍦ˋction涓氨鍙互鏍規(guī)嵁榪欎袱涓弬鏁板幓鍙栦笅涓涓〉闈笂瑕佹樉紺虹殑璁板綍闆嗕簡銆?
Jsp涓婁紶欏甸潰錛?
聽
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
strutsUploadForm
</title>
</head>
<body bgcolor="#ffffff">
<h1>
涓婁紶嫻嬭瘯
</h1>
<form action="uploadTestAction.do" method="post" enctype="multipart/form-data" name="form1">
聽 <p>鏂囨湰
聽聽聽 <input name="theText" type="text" id="theText">
</p>
聽 <p>鏂囦歡
聽聽聽 <input name="theFile" type="file" id="theFile">
</p>
聽 <p>淇濆瓨鍒?
聽聽聽 <input name="saveTo" type="text" id="saveTo">
</p>
聽 <p>
聽聽聽 <input type="submit" name="Submit" value="鎻愪氦">
</p>
</form>
</body>
</html>
聽
聽
actionForm
聽
package hehe;
聽
import org.apache.struts.action.*;
import javax.servlet.http.*;
import org.apache.struts.upload.FormFile;
聽
public class UploadTestForm extends ActionForm {
聽 private String saveTo;
聽 private String theText;
聽 private org.apache.struts.upload.FormFile theFile;//鏂囦歡妗嗗搴旂殑鏄痜ormFile綾誨瀷
聽 public String getSaveTo() {
聽聽聽 return saveTo;
聽 }
聽 public void setSaveTo(String saveTo) {
聽聽聽 this.saveTo = saveTo;
聽 }
聽 public org.apache.struts.upload.FormFile getTheFile() {
聽聽聽 return theFile;
聽 }
聽 public void setTheFile(org.apache.struts.upload.FormFile theFile) {
聽聽聽 this.theFile = theFile;
聽 }
聽 public String getTheText() {
聽聽聽 return theText;
聽 }
聽 public void setTheText(String theText) {
聽聽聽 this.theText = theText;
聽 }
聽 public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
聽聽聽 /**@todo: finish this method, this is just the skeleton.*/
聽聽聽 if(!this.getTheFile().getContentType().equals("image/pjpeg")){
聽聽聽聽聽 System.out.println("涓嶆槸jpg");
聽聽聽 }//鍙互鍒ゆ柇綾誨瀷
聽聽聽 if(this.getTheFile().getFileSize()>100){
聽聽聽聽聽 System.out.println("闀垮害澶т簬1000");
聽聽聽 }//鍙互鍒ゆ柇澶у皬
聽聽聽 return null;
聽 }
聽 public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
聽聽聽 saveTo = null;
聽聽聽 theFile = null;
聽聽聽 theText = null;
聽 }
}
聽
聽
Action
聽
package hehe;
聽
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
import javax.servlet.http.*;
import java.io.*;
聽
public class UploadTestAction
聽聽聽 extends Action {
聽 public ActionForward execute(ActionMapping actionMapping,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ActionForm actionForm,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 HttpServletRequest request,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 HttpServletResponse response) {
聽聽聽 UploadTestForm uploadForm = (UploadTestForm) actionForm;
聽聽聽 FormFile file = uploadForm.getTheFile();
聽聽聽 String path = uploadForm.getSaveTo();
聽聽聽 String theText = uploadForm.getTheText();
聽聽聽 try {
聽聽聽聽聽 InputStream input = file.getInputStream();//鑳戒粠FormFile涓幏寰楄緭鍏ユ祦
聽聽聽聽聽 OutputStream output = new FileOutputStream(path);
聽聽聽聽聽 int bytesReader = 0;
聽聽聽聽聽 byte[] readbuffer = new byte[8192];
聽聽聽聽聽 while ( (bytesReader = input.read(readbuffer, 0, 8192)) != -1) {
聽聽聽聽聽聽聽 output.write(readbuffer, 0, bytesReader);
聽聽聽聽聽 }
聽聽聽聽聽 output.close();
聽聽聽 }
聽聽聽 catch (Exception e) {
聽聽聽聽聽 e.printStackTrace();
聽聽聽 }
聽聽聽 request.setAttribute("theText", theText);
聽聽聽 request.setAttribute("fileName", file.getFileName());//涓婁紶鐨勬枃浠跺悕
聽聽聽 request.setAttribute("fileSize", new Integer(file.getFileSize()));//鏂囦歡澶у皬
聽聽聽 request.setAttribute("fileType", file.getContentType());//鏂囦歡綾誨瀷
聽聽聽 return actionMapping.findForward("success");
聽 }
}
聽
聽
緇撴灉欏甸潰
聽
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
strutsUploadResult
</title>
</head>
<body bgcolor="#ffffff">
<h1>
涓婁紶緇撴灉
</h1>
鏂囦歡鍚嶏細<%=request.getAttribute("fileName")%><br />
鏂囨湰錛?lt;%=request.getAttribute("theText")%><br />
鏂囦歡綾誨瀷錛?lt;%=request.getAttribute("fileType")%><br />
鏂囦歡澶у皬錛?lt;%=request.getAttribute("fileSize")%><br />
</body>
</html>
java
浠g爜
:聽
|
|
鍦ㄧ▼搴忎腑瀹氫箟閿欒鍜屼俊鎭被
,
榪欎釜渚嬪瓙鍐欏湪
JSP
涓?/span>
java
浠g爜
:聽
|
|
鏄劇ず閿欒
:
java
浠g爜
:聽
|
|
鏄劇ず淇℃伅
:
java
浠g爜
:聽
|
|
2.瀵逛簬鍙傛暟鍊間笉紜畾鐨勶紝paramName鍜宲aramProperty鏉ヨ緭鍑猴紝鐢╬aramId灞炴ф寚瀹氬弬鏁板悕銆?br />瀵逛簬paramName鎸囧畾鐨勫璞″簲璇ュ瓨鍦ㄤ簬page銆乺equest銆乻ession銆乤pplication鍏朵腑涔嬩竴銆備竴鑸潵璇達紝鏄粠Action綾諱紶榪囨潵鐨勶紝浣滀負request鐨勫睘鎬т箣涓錛坮equst.setAttribute("name",object)錛夈?br />濡傛灉paramName鎸囧畾鐨勫璞℃槸action鐨凙ctionForm錛屽垯鏃犻渶浣跨敤request.setAttribute鏂規(guī)硶銆?br />渚嬶細<html:link page="/test.do" paramId="userid" paramName="uid">uname</html:link>
鑻ュ弬鏁板兼槸涓涓猙ean瀵硅薄鐨勫睘鎬у鹼紙姣斿ActionForm,鎴栬呴泦鍚堜腑瀛樻斁鐨勫璞★級鍒欙細
<html:link page="/test.do" paramId="userid" paramName="user" paramProperty="uid">uname</html:link>
3.鑻ヤ袱涓弬鏁幫紝涓涓‘瀹氫竴涓笉紜畾錛屽垯鏄互涓婁袱縐嶆柟娉曠殑緇撳悎錛屽嵆錛?br /><html:link page="/test.do?action=modify" paramId="userid" paramName="uid">modify</html:link>
4.瀵逛簬澶氫釜鍙傛暟鐨勯棶棰橈紝鍙互浣跨敤涓涓狧ashMap闆嗗悎瀵硅薄鏉ュ瓨鏀炬墍鏈夌殑鍙傛暟鍚嶅強瀵瑰簲鐨勫弬鏁板肩殑鏂瑰紡錛宲aramName灞炴у兼寚瀹氫負璇ashMap闆嗗悎瀵硅薄鍗沖彲銆?br />涓句緥錛?br /><%
//浠g爜鐞嗘兂鐨勪綅緗簲璇ユ槸鍦╝ction涓?br />//鍙互鍦╦sp欏甸潰嫻嬭瘯
聽 java.util.HashMap pms = new java.util.HashMap();
聽 pms.put("code", "001002");
聽 pms.put("name", "tester");
聽 pms.put("alias", new String[]{"matin","jack"});
聽 request.setAttribute("params", pms);
%>
<html:link action="/test.do" name="params" >test</html:link>
緙栬瘧鍚庣殑緇撴灉錛?lt;a href="/test.do?code=001002&name=tester&alias=matin&alias=jack">test</a>
榪欑鏂瑰紡铏界劧鍙互瑙e喅浼犲鍙傛暟鐨勯棶棰橈紝浣嗘槸瀹炵幇璧鋒潵涔熸瘮杈冮夯鐑︼紝鐗瑰埆鏄璁板綍闆嗕腑鐨勬暟鎹愭潯鍒楀嚭鐨勬椂鍊?/p>
5.閽堝鏈夌殑緗戝弸鍦?lt;html:link>鏍囩涓祵鍏ヤ嬌鐢╦sp鑴氭湰(scriptlet)鐨勯棶棰橈紝
渚嬪:
<html:link page="/test.do?code=<%=varible%>">add</html:link>錛岃繖縐嶅啓娉曟槸閿欒鐨勶紝鏄棤娉曠紪璇戠殑銆?br />鏈夌殑緗戝弸璁や負鍦╯truts鏍囩鍐呮槸涓嶅厑璁鎬嬌鐢╦sp鑴氭湰鐨勶紝榪欑璇存硶涔熶笉鍑嗙‘銆傚鏋滃墠闈㈢殑鍐欐硶鏀規(guī)垚:
<html:link page="<%="/test.do?code="+varible%>">add</html:link>錛屽氨鍙互琚墽琛岋紝浣嗘槸瑕佹敞鎰廢RL鐩稿璺緞鐨勯棶棰樸?/p>
铏界劧鍦╯truts鏍囩涓祵鍏sp鑴氭湰涓嶆槸鐪熸鎰忎箟涓婄殑struts搴旂敤錛屼絾鏄湁鏃跺湪濮旀洸姹傚叏鐨勬儏鍐典笅涔熷彧鑳藉姝や簡錛岄櫎闈炰嬌鐢ㄨ嚜瀹氫箟鏍囩銆傛瘮濡傚湪form琛ㄥ崟涓彲鑳介渶瑕佹牴鎹叿浣撴暟鎹鏌愪釜瀛楁鏄彧璇葷殑錛屽氨鍙互鐢ㄥ祵鍏sp鑴氭湰鏉ュ疄鐜幫細
<%
boolean rdonly=false;
if(2==2) rdonly=true;
%>
<html:text property="userid" readonly="<%=rdonly%>" />
6.鍙﹀涓縐嶆瘮杈冨彉鎬佺殑鏂規(guī)硶錛屾棦涓嶆槸鐪熸鎰忎箟涓婄殑struts錛屼篃涓嶇鍚坸ml瑙勮寖銆傞偅灝辨槸鍦?lt;a>鏍囩涓敤<bean:write>鏍囩杈撳嚭鍙傛暟鍊箋?br />濡傦細<a href="test.do?uid=<bean:write name="user" property="userid"/>&name=<bean:write name="user" property="username"/>">test</a>