http://www.verejava.com/?id=1699017804881
1.打开 Eclipse 新建一个 test 项目 Eclipse -> File -> New -> Dynamic Web Project
2.在 test/WebContent 下面新建一个 user.jsp 文件
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
姓名:<%=request.getAttribute("name") %>
性别:<%=request.getAttribute("gender") %>
月薪:<%=request.getAttribute("salary") %>
爱好:<%=request.getAttribute("interest") %>
<hr>
<form action="user!add" method="post" >
姓名:<input type="text" name="name" />
性别:<input type="radio" name="gender" value="1" />男 <input type="radio" name="gender" value="2" />女
月薪:
<select name="salary">
<option value="20000">20000</option>
<option value="30000">30000</option>
<option value="40000">40000</option>
<option value="50000">50000</option>
</select>
爱好:<input type="checkbox" name="interest" value="唱歌" />唱歌 <input type="checkbox" name="interest" value="篮球" />篮球
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
3.在 test/src 下面新建一个 com.test.action.UserAction 类
package com.test.action;
import javax.servlet.http.HttpServletRequest;
import com.vere.mvc.ServletActionContext;
import com.vere.mvc.util.CParam;
public class UserAction {
public String execute() {
return "success";
}
public String add() {
HttpServletRequest request = ServletActionContext.getRequest();
String name=CParam.getString(request, "name");
int gender=CParam.getInt(request, "gender");
long salary=CParam.getLong(request, "salary");
String interest=CParam.getStrings(request, "interest");
request.setAttribute("name", name);
request.setAttribute("gender", gender);
request.setAttribute("salary", salary);
request.setAttribute("interest", interest);
return "success";
}
}
4.在 test/src/VereMVC.xml 里面配置Action
<?xml version="1.0" encoding="UTF-8"?>
<VereMVC>
<constant name="charset" value="utf-8" />
<constant name="developMode" value="true" />
<constant name="language" value="en_US" />
<action name="user" class="com.test.action.UserAction">
<result name="success">/user.jsp</result>
<result name="add">/user.jsp</result>
</action>
</VereMVC>
5.在 浏览器地址栏输入 http://localhost:8080/test/user