jsp如何与Java进行数据传递

随风而醒 2017-04-06 12:10:35
jsp中是这样的:
<div id="r-result">
用户名: <input id="cityName" type="text"
style="width: 100px; margin-right: 10px;" /> <input type="button"
value="定位" onclick="theLocation()" />
</div>


Java中函数处理是:获取jsp中的cityName值,返回一个链表到jsp,然后jsp对链表在进行操作

问一下有什么办法?
...全文
818 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
仵夨飞鸟汐 2017-04-07
  • 打赏
  • 举报
回复
<form action="URL请求" method="post" > -------------------------利用form表单发送post请求---------------------- 至于input type 改成submit </form>
随风而醒 2017-04-07
  • 打赏
  • 举报
回复
引用 9 楼 CORA_S_T 的回复:
JSP:

<body>
    <form action="GetInfo" method="get">
        <input name="cityName" type="text">
        <input type="submit" value="定位"> 
    </form>
</body>

Servlet:

	@WebServlet("/GetInfo")
public class GetInfo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetInfo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String cityName = request.getParameter("cityName");
		System.out.println(cityName);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
非常感谢!!已经写好了。
千杯不醉476 2017-04-07
  • 打赏
  • 举报
回复
JSP:

<body>
    <form action="GetInfo" method="get">
        <input name="cityName" type="text">
        <input type="submit" value="定位"> 
    </form>
</body>

Servlet:

	@WebServlet("/GetInfo")
public class GetInfo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetInfo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String cityName = request.getParameter("cityName");
		System.out.println(cityName);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
JustWantMa 2017-04-06
  • 打赏
  • 举报
回复
不管你是怎么学的,都应该会有表单提交吧
ZeWe 2017-04-06
  • 打赏
  • 举报
回复
用servlet写后台程序!你学一下servlet就行咯
随风而醒 2017-04-06
  • 打赏
  • 举报
回复
引用 3 楼 lrx2011 的回复:
前台用submit或ajax提交下,后台用reques.getParameter获取
能具体说一下吗?或者给个例子,谢谢
随风而醒 2017-04-06
  • 打赏
  • 举报
回复
引用 1 楼 computerclass 的回复:
后台用Java 接收一下不就行了
如何接受?能具体说下吗?或者给一个参考链接,谢谢
podd 2017-04-06
  • 打赏
  • 举报
回复
前台用submit或ajax提交下,后台用reques.getParameter获取
随风而醒 2017-04-06
  • 打赏
  • 举报
回复
如何接受?能具体说明一下吗?或者给一个参考链接,谢谢
computerclass 2017-04-06
  • 打赏
  • 举报
回复
后台用Java 接收一下不就行了

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧