表单处理的方案与注意事项(servlet)

摘要

表单是后端程序员用的与接触最多的,我这里例举了常用处理办法,与注意事项


sevlet处理代码

package myform;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class resvrcData extends HttpServlet { @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
// super.doGet(req, resp);
doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
// super.doPost(req, resp);
resp.setContentType("text/html;charset=UTF-8");
resp.setCharacterEncoding("UTF-8");
PrintWriter writer = resp.getWriter();
Enumeration<String> names = req.getParameterNames();
String parameter = req.getParameter("r");
//System.out.println(parameter);
while (names.hasMoreElements()) {
//writer.write(names.nextElement());
writer.write(req.getParameter(names.nextElement()));
}
writer.close();
} }

注意

我看了类似网上代码,忽略写servlet配置文件 在html写数据到servlet是会报404 错误代码的 所以必须配置

表单处理的方案与注意事项(servlet)

radiobox

表单处理的方案与注意事项(servlet)

checkbox

表单处理的方案与注意事项(servlet)

select

        <center>
<!-- name的值相同才能做相同绑定 multiple="multiple"-->
<form method="post" action="/SessionTchCookies/myform/resvrcData.do">
<select name="select1" >
<option value="o1">1</option>
<option value="o2">2</option>
<option value="o3">3</option>
<option value="o4">4</option>
</select>
<input type="submit" value="提交"/>
</form>
</center>

包含optgroup表单的属性设置

<form method="post" action="/SessionTchCookies/myform/resvrcData.do">
<br>
<br> <select name="test" id="select">
<ins>ss</ins>
<optgroup label="num">
<option value="11" disabled>1</option>
<option value="22" selected>2</option>
<option value="33">3</option>
<option value="44" label="word">4</option>
</optgroup>
<optgroup label="word">
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</optgroup>
<optgroup label="汉字" disabled>
<option value="一个">一</option>
<option value="二个">二</option>
<option value="三个">三</option>
<option value="四个">四</option>
</optgroup>
</select> <input type="submit">
上一篇:用 ArcMap 发布 ArcGIS Server Feature Server Feature Access 服务 SQL Server版


下一篇:Mac安装wget