struts2 的3种驱动 第一种方式
[size=x-large]第一种是:将所有的属性都写在action中:[/size] [color=red]在action中 我只写了一个属性username : action 中的内容:[/color] package com.luhua.test; public class UserAction { //用户名 private String username ; public void setUsername(String username) { this.username = username; } public String execute(){ return "success" ; } public String user(){ System.out.println(username); //这里接收的是页面上传过来的值 return "success" ; } } [color=red]在struts.xml中的配置是:[/color] index.jsp success.jsp [color=red]jsp页面有两张,index.jsp 和 success.jsp 从index.jsp中输入用户名; 在action中打印出来[/color] [color=red]index.jsp:[/color] <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
username:
[color=red]success.jsp[/color] <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> user