SSH 项目中,action获取jsp页面传过来的select值
项目框架S2SH,jsp页面如下,select列表设为multiple。为了能在action里取到前台界面select列表的多选值,瞎搞了两天,今天终于成功。其实后台action取前台jsp页面的值很简单,废话不多说,先贴代码:
<body>
<form action="sendMsg.action?senderId=${users.id }&username=${users.username}" method="post"
id="form" name="form" onsubmit="getIdValue()">
<input type="hidden" value="" name="" id="ids" />
<table width="500" height="220" border="1" align="center">
<tr>
<td colspan="2">
【欢迎使用】
</td>
</tr>
<tr>
<td width="88">
标题:
</td>
<td width="396">
<input type="text" name="title" id="title" />
</td>
</tr>
<tr>
<td>
内容:
</td>
<td>
<textarea name="content" id="content" cols="45" rows="5">
接收者:
${t}
action代码:
...
//定义一个与jsp页面相同的变量
private String userId; //setter getter方法略
...
public String sendMsg() throws Exception{
String username = ServletActionContext.getRequest().getParameter("username"); //获取用户名
String t[] = ServletActionContext.getRequest().getParameterValues("userId"); //这里获取时,变量名就直接写jsp页面的就行。
System.out.println(t[0]); //测试输出成功
System.out.println(t[1]);
相关文档:
Jsp 连接 mySQL、Oracle 数据库备忘
2009-12-15 16:47
Jsp 环境目前最流行的是 Tomcat5.0。Tomcat5.0 自己包含一个 Web 服务器,如果是测试,就没必要把 Tomcat 与 IIS 或 Apache 集成起来。在 Tomcat 自带的 Web 服务器下可以进行 Jsp 测试。
安装 Tomcat5.0 前需要安装 JDK(如果是 Windows server ......
Jsp连接MSSQL2000的两种方法
最近在学习JSPWeb(Tomcat服务器)应用开发和基于Weblogic和Myelcipse的JEE5的开发,在学习过程中涉及到连接SQL 2000 数据库时,由于软件环境的差异性和一些版本问题,花了好大功夫才连上,所以在此作个总结,希望能给大家一些帮助,不要在基本的东西上花费太多的时间。
方法一:利用SQL Se ......
实现JSP自定义标签的一种方法:
1.写一个类继承TagSupport或其他Tag的实现类。
public class AllTag extends TagSupport {
@Override
public int doStartTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
out.append("Hello World.");
} catch (IOException e) {
e.pri ......
required 是是否为必选属性
rtexprvalue的全称是 Run-time Expression Value, 它用于表示是否可以使用JSP表达式.
当在<attribute>标签里指定<rtexprvalue>true</rtexprvalue>时, 表示该自定义标签的某属性的值可以直接指定或者通过动态计算指定, example as follow:
<sql:query var="result" & ......
自己分页,下一篇会介绍使用diasplaytag组件。
使用mysql5, 有个数据表user,字段有id, username, password。
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional// ......