求一个Java Serlvet服务器端,能接受POST请求就好。其实什么编程语言都可以的!
展开全部
Servlet中有继承的POST方法的 doPOST(),然后当一个表单提交数据的时候它就能获得里面的数据~~然后记得在WEB.XML进行SERVLET的配置,得让它找到这个Servlet!!!
<form action="/doPostt_servlet" method="post">
………
<textarea cols="50" rows="10"></textarea>
………
</form>
servlet代码:
public class doPostt_servlet extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse esponse) throws IOException,ServletException {
request.setCaracterEncoding(“gb2312”);//汉字转码
PrintWriter out = response.getWriter();
out.println("The Parameter are :"+request.getParameter("name2"));
}
}
<form action="/doPostt_servlet" method="post">
………
<textarea cols="50" rows="10"></textarea>
………
</form>
servlet代码:
public class doPostt_servlet extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse esponse) throws IOException,ServletException {
request.setCaracterEncoding(“gb2312”);//汉字转码
PrintWriter out = response.getWriter();
out.println("The Parameter are :"+request.getParameter("name2"));
}
}
追问
如何配置web.xml?不懂tomcat啊
展开全部
package com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.xml.DOMConfigurator;
public class GetYEServlet extends HttpServlet {
public GetYEServlet() {
super();
}
public void destroy() {
super.destroy();
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
String sname = request.getParameter("sname");
}
public void init() throws ServletException {
// Put your code here
}
}
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.xml.DOMConfigurator;
public class GetYEServlet extends HttpServlet {
public GetYEServlet() {
super();
}
public void destroy() {
super.destroy();
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
String sname = request.getParameter("sname");
}
public void init() throws ServletException {
// Put your code here
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询