java的struts2中怎样获取request中的文件与文件中的所有信息

java的struts2中怎样获取request中的文件与文件中的所有信息,第1张

ActionContext.getContext().getSession().get("你要老信获取的属性名称")

ActionContext.getContext().get("你要获取的属性名称")

使用上述方法可以获得,下面是辅助说明。

在Struts2开发中,除了将请求参数自动设置到Action的字毕含山段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息,甚至需要直接对JavaServlet Http的请求手中(HttpServletRequest),响应(HttpServletResponse) *** 作. 我们需要在Action中取得request请求参数"username"的值:

[java]

ActionContext context = ActionContext.getContext()

Map params = context.getParameters()

String username = (String) params.get("username")

ActionContext context = ActionContext.getContext()

Map params = context.getParameters()

String username = (String) params.get("username")

表单中form 下的action提交到什么地方(陪氏枯一般核碰是到一个servlet里面),芦洞在那个.Java文件里用request.getParameter() 方法来得到表单中输入的数据。例如:

<form action="servlet/Login" method="get">

用户名:<input type="text" name="username" /><br>

密码:<input type="password" name="password"><br></form>

那么在Login.java中得需要String username=request.getParameter("username")和

String password = request.getParameter("password")来得到输入的用户名和密码

注意:getParameter()方法括号中要和表单中这两个的name相对应才行


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12117752.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存