珀淳奶粉通过婴幼儿奶粉配方对比表注册制了吗

关于struts2标签获取后台action中变量值的书写格式 - ITeye问答
初学者....多多指教!
问题:
struts2标签在获得后台action中的变量值时怎么在jsp中书写;
例如:我想用&s:property value=/&
中获取action中变量名为allen的变量的值,当然action中有了相应的get和set的方法。
假如是获取的是对象又是怎么样?
疑惑:我看了很多代码上有的是这么写的
&s:property value="#allen"/&
&s:property value="%{allen}"/&
&s:property value="%{#allen}"/&
等等& 时灵时不灵& 到底它在页面上是怎么书写获取变量值的呢?
采纳的答案
OGNL是通常要结合Struts 2的标志一起使用。主要是#、%和$这三个符号的使用。使用方法如下:
新建名为OGNL的Web工程
“#”主要有三种用途:
访问OGNL上下文和Action上下文,#相当于ActionContext.getContext();下表有几个ActionContext中有用的属性:&& 名称 作用 例子
parameters 包含当前HTTP请求参数的Map #parameters.id[0]作用相当于request.getParameter("id")
request 包含当前HttpServletRequest的属性(attribute)的Map #request.userName相当于request.getAttribute("userName")
session 包含当前HttpSession的属性(attribute)的Map #session.userName相当于session.getAttribute("userName")
application 包含当前应用的ServletContext的属性(attribute)的Map #application.userName相当于application.getAttribute("userName")
attr 用于按request & session & application顺序访问其属性(attribute) #attr.userName相当于按顺序在以上三个范围(scope)内读取userName属性,直到找到为止
用于过滤和投影(projecting)集合,如books.{?#this.price&100};
构造Map,如#{'foo1':'bar1', 'foo2':'bar2'}。
“%”符号的用途是在标志的属性为字符串类型时,计算OGNL表达式的值。
“$”有两个主要的用途,用于在国际化资源文件中,引用OGNL表达式。在Struts 2配置文件中,引用OGNL表达式。
简单的标签使用:&br&
request.setAttribute("name","OGNL");
session.setAttribute("s_name","会话_山东新华");
使用#取出数据:&br&
#request.name:&&&&s:property value="#request.name"/&
#session.s_name:&&&&s:property value="#session.s_name"/&
使用s:set声明一个map对像:&br&
&s:set name="map" value="#{'name':'sdxh','age':'21'}"/&
取出map中的数据&&&&&&&&&&&&&&:&s:property value="#map['name']"/&
使用%可以对一个字符串类型进行计算:&br&
没有使用%号的情况&&&&&&&&&&&&:&s:url value="#map['age']"/&&br&
使用%的情况&&&&&&&&&&&&&&&&&&:&s:url value="%{#map['age']}"/&
————————————————————————————
对象的形式
&s:form action="userAction" method="post"&
&s:form action="for03" method="post"&
&s:textfield label="姓名" name="user.name"&&/s:textfield&
&s:textfield label="年龄" name="user.age"&&/s:textfield&
&s:submit&&/s:submit&
public class UserAction {
public User getUser() {
public void setUser(User user) {
this.user =
已解决问题
未解决问题I am new to Android and trying to get HTML content of a web page and that is when I came across this issue.
java.lang.IllegalStateException: Cannot set request property after connection is made
public static String getHTMLPage(String inputURL, String host, String referer, String cookie, String breakString) {
String htmlContent = "";
URL u = new URL(inputURL);
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
uc.setRequestProperty("Host", host);
uc.setRequestProperty("Connection", "keep-alive");
if (!referer.isEmpty()) {
uc.setRequestProperty("Referer", referer);
uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1");
uc.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/q=0.9,*/*;q=0.8");
uc.setRequestProperty("Accept-Encoding", "html");
uc.setRequestProperty("Accept-Language", "en-US,q=0.8");
uc.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
if (!cookie.isEmpty()) {
uc.setRequestProperty("Cookie", cookie);
BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String line = "";
while ((line = br.readLine()) != null) {
if (!breakString.isEmpty() && line.contains(breakString)) {
htmlContent +=
br.close();
} catch (Exception e) {
System.out.println(e);
return htmlC
Basically, I have written this in a pure java application (where it is working fine) and I just wanted to re-use the same. I have googled and found few SO pages (,,,), but none of them addresses the problem specific to HTTPURLConnection directly. (Though, some advised about HTTPClient, which is found to be deprecated which I don't want to use.)
Adding getResponseCode() is returning the value as 200 successfully.
System.out.println("RESPONSE CODE : "+uc.getResponseCode());
I have looked the
page and which states
public void setRequestProperty (String field, String newValue)
Sets the value of the specified request header field. The value will
only be used by the current URLConnection instance. This method can
only be called before the connection is established.
How I can set the request property before making the connections ? As per the code, we are getting the HTTPURLConnection object only after opening connection for a specific URL (and casting it with HTTPURLConnection)
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
What is the correct way to use HTTPURLConnection to read HTML page along with setRequestProperty ?
解决方案 The connection isn't created by 'URL.openConnection().` It is created when you get the input or error stream or the response code.
NB you shouldn't call setDoOutput(true) unless you are going to do output, which you aren't here. It sets the HTTP method to POST.
本文地址: &
我是新来的Android和试图获得一个网页的HTML内容,这是当我碰到这个问题。
java.lang.IllegalStateException:不能设置请求属性连接后
公共静态字符串getHTMLPage(字符串inputURL,主机字符串,字符串引荐,cookie的字符串,字符串breakString){
串htmlContent =“”;
URL U =新的URL(inputURL);
HttpURLConnection的UC =(HttpURLConnection类)u.openConnection();
uc.setRequestProperty(“主机”,主机);
uc.setRequestProperty(“连接”,“保持活动”);
如果(!referer.isEmpty()){
uc.setRequestProperty(“引荐”,引用者);
uc.setRequestProperty(“用户代理”,“Mozilla的/ 5.0(Windows NT的5.1)为AppleWebKit / 535.1(KHTML,像壁虎)的Chrome / Safari浏览器13.0.782.112 / 535.1”);
uc.setRequestProperty(“接受”,“text / html的,是application / xhtml + xml的,应用/ XML; Q = 0.9 * / *; Q = 0.8”);
uc.setRequestProperty(“接受编码”,“HTML”);
uc.setRequestProperty(“接受语言”,“EN-US,连接; Q = 0.8”);
uc.setRequestProperty(“接收字符集”,“ISO-8859-1,utf-8的; Q = 0.7,*; Q = 0.3”);
如果(!cookie.isEmpty()){
uc.setRequestProperty(“曲奇”饼干);
BR的BufferedReader =新的BufferedReader(新的InputStreamReader(uc.getInputStream()));
串线=“”;
而((行= br.readLine())!= NULL){
如果(breakString.isEmpty()及!&放大器; line.contains(breakString)){
htmlContent + =行;
br.close();
}赶上(例外五){
的System.out.println(E);
返回htmlC} 基本上,我已经在纯的Java 应用程序(它是工作的罚款),写了这个,我只是想再次使用相同的。我用Google搜索,发现几页的篇幅(1,,,),但他们没有涉及具体到 HttpURLConnection类直接(尽管这一问题,一些建议约了HTTPClient ,它被发现被德precated,我不想使用。)添加 GETRESPONSE code()的返回值200成功。 的System.out.println(“响应code:”+ uc.getResponse code()); 我已经看过了参考页,其中规定 公共无效调用setRequestProperty(String域,字符串newValue)以
设定指定的请求头字段的值。该值将
仅由当前的URLConnection实例使用。这种方法可以
在建立连接之前只能被称为如何设置连接前请求属性?由于每code,我们只 HttpURLConnection类)
HttpURLConnection的UC =(HttpURLConnection类)u.openConnection(); 什么是正确的使用方法 HttpURLConnection类与调用setRequestProperty 陪读HTML页面? 解决方案 不被'URL.openConnection()创建的连接。'当你输入或错误流或响应code已创建 NB,你不应该叫 setDoOutput(真),除非你打算怎么办输出,你是不是在这里。它集HTTP方法POST。
本文地址: &
扫一扫关注官方微信标签:至少1个,最多5个
(看到一篇调试JS很有用的文章,收藏一下)
JavaScript 调试是一场噩梦:首先给出的错误非常难以理解,其次给出的行号不总有帮助。有个查找错误含义,及修复措施的列表,是不是很有用?
以下是奇怪的 JavaScript 错误列表。同样的错误,不同的浏览器会给出不同的消息,因此有一些不同的例子。
如何读懂错误?
首先,让我们快速看下错误信息的结构。理解结构有助于理解错误,如果遇到列表之外的错误会减少麻烦。
Chrome 中典型的错误像这样:
Uncaught TypeError: undefined is not a function
错误的结构如下:
Uncaught TypeError: 这部分信息通常不是很有用。Uncaught 表示错误没有被 catch 语句捕获,TypeError 是错误的名字。
undefined is not a function: 这部分信息,你必须逐字阅读。比如这里表示代码尝试使用 undefined ,把它当做一个函数。
其它基于 webkit 的浏览器,比如 Safari ,给出的错误格式跟 Chrome 很类似。Firefox 也类似,但是不总包含第一部分,最新版本的 IE 也给出比 Chrome 简单的错误 - 但是在这里,简单并不总代表好。
以下是真正的错误。
Uncaught TypeError: undefined is not a function
相关错误:
number is not a function, object is not a function, string is not a function, Unhandled Error: ‘foo’ is not a function, Function Expected
当尝试调用一个像方法的值时,这个值并不是一个方法。比如:
如果你尝试调用一个对象的方法时,你输错了名字,这个典型的错误很容易发生。
var x = document.getElementByID('foo');
由于对象的属性不存在,默认是 undefined ,以上代码将导致这个错误。尝试调用一个像方法的数字,“number is not a function” 错误出现。
如何修复错误:确保方法名正确。这个错误的行号将指出正确的位置。
Uncaught ReferenceError: Invalid left-hand side in assignment
相关错误:
Uncaught exception: ReferenceError: Cannot assign to ‘functionCall()’, Uncaught exception: ReferenceError: Cannot assign to ‘this’
尝试给不能赋值的东西赋值,引起这个错误。
这个错误最常见的例子出现在 if 语句使用:
if(doSomething() = 'somevalue')
此例中,程序员意外地使用了单个等号,而不是双等号。“left-hand side in assignment” 提及了等号左手边的部分,因此你可以看到以上例子,左手边包含不能赋值的东西,导致这个错误。
如何修复错误:确保没有给函数结果赋值,或者给 this 关键字赋值。
Uncaught TypeError: Converting circular structure to JSON
相关错误:
Uncaught exception: TypeError: JSON.stringify: Not an acyclic Object, TypeError: cyclic object value, Circular reference in value argument not supported
把循环引用的对象,传给 JSON.stringify 总会引起错误。
var a = { };
var b = { a: a };
JSON.stringify(a);
由于以上的 a 和 b 循环引用彼此,结果对象无法转换成 JSON。
如何修复错误: 移除任何想转换成 JSON 的对象中的循环引用。
相关错误:
Expected ), missing ) after argument list
JavaScript 解释器预期的东西没有被包含。不匹配的圆括号或方括号通常引起这个错误,错误信息可能有所不同 - “Unexpected token ]” 或者 “Expected {” 等。
如何修复错误: 有时错误出现的行号并不准确,因此很难修复。
[ ] { } ( ) 这几个符号不配对常常导致出错。检查所有的圆括号和方括号是否配对。行号指出的不仅是问题字符。
Unexpected / 跟正则表达式有关。此时行号通常是正确的。
U 对象或者数组字面量里面有个;通常引起这个错误,或者函数调用的参数列表里有个分号。此时的行号通常也是正确的。
Uncaught SyntaxError: Unexpected token ILLEGAL
相关错误:
Unterminated String Literal, Invalid Line Terminator
一个字符串字面量少了结尾的引号。
如何修复错误: 确保所有的字符串都有结束的引号。
Uncaught TypeError: Cannot read property ‘foo’ of null, Uncaught TypeError: Cannot read property ‘foo’ of undefined
相关错误:
TypeError: someVal is null, Unable to get property ‘foo’ of undefined or null reference
尝试读取 null 或者 undefined ,把它当成了对象。例如:
var someVal =
console.log(someVal.foo);
如何修复错误: 通常由于拼写错误导致。检查错误指出的行号附近使用的变量名是否正确。
Uncaught TypeError: Cannot set property ‘foo’ of null, Uncaught TypeError: Cannot set property ‘foo’ of undefined
相关错误:
TypeError: someVal is undefined, Unable to set property ‘foo’ of undefined or null reference
尝试写入 null 或者 undefined ,把它当成了一个对象。例如:
var someVal =
someVal.foo = 1;
如何修复错误: 也是由于拼写错误所致。检查错误指出的行号附近的变量名。
Uncaught RangeError: Maximum call stack size exceeded
相关错误:
Related errors: Uncaught exception: RangeError: Maximum recursion depth exceeded, too much recursion, Stack overflow
通常由程序逻辑 bug 引起,导致函数的无限递归调用。
如何修复错误: 检查递归函数中可能导致无限循环 的 bug 。
Uncaught URIError: URI malformed
相关错误:
URIError: malformed URI sequence
无效的 decodeURIComponent 调用所致。
如何修复错误: 按照错误指出的行号,检查 decodeURIComponent 调用,它是正确的。
XMLHttpRequest cannot load [http://some/url/](http://some/url/). No ‘Access-Control-Allow-Origin’ header is present on the requested resource
相关错误:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
[http://some/url/](http://some/url/)
错误肯定是使用 XMLHttpRequest 引起的。
如何修复: 确保请求的 URL 是正确的,它遵循 。最好的方法是从代码中找到错误信息指出的 URL 。
InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable
相关错误:
InvalidStateError, DOMException code 11
代码调用的方法在当前状态无法调用。通常由 XMLHttpRequest 引起,在方法准备完毕之前调用它会引起错误。
var xhr = new XMLHttpRequest();
xhr.setRequestHeader('Some-Header', 'val');
这时就会出错,因为 setRequestHeader 方法只能在 xhr.open 方法之后调用。
如何修复: 查看错误指出的行号,确保代码运行的时机正确,或者在它(例如 xhr.open)之前添加了不必要的调用
我看过不少无用的 JavaScript 错误,比如 PHP 中声名狼藉的异常 Expected T_PAAMAYIM_NEKUDOTAYIM 。抛出更熟悉的错误才更有意义。现代浏览器不再抛出完全无用的错误,才会更有帮助。
原文Jani Hartikainen - 《》
翻译出处: -
8 收藏&&|&&90
你可能感兴趣的文章
1 收藏,203
1 收藏,848
104 收藏,
分享到微博?
技术专栏,帮你记录编程中的点滴,提升你对技术的理解收藏感兴趣的文章,丰富自己的知识库
明天提醒我
我要该,理由是:
扫扫下载 App//第一种很少用public&class&LoginAction1&extends&ActionSupport&{&&&&&&&&private&Map&&&&&private&Map&&&&&private&Map&&&&&&&&&public&LoginAction1()&{&&&&&&&&request&=&(Map)ActionContext.getContext().get("request");&&&&&&&&session&=&ActionContext.getContext().getSession();&&&&&&&&application&=&ActionContext.getContext().getApplication();&&&&}&&&&&&&&public&String&execute()&{&&&&&&&&request.put("r1",&"request1");&&&&&&&&session.put("s1",&"session1");&&&&&&&&application.put("a1",&"application1");&&&&&&&&return&SUCCESS;&&&&&}}//第二种几乎都用这种方式public&class&LoginAction2&extends&ActionSupport&implements&RequestAware,SessionAware,&ApplicationAware&{&&&&&&&&private&Map&String,&Object&&&&&&private&Map&String,&Object&&&&&&private&Map&String,&Object&&&&&&&&&&//DI&dependency&injection&&&&//IoC&inverse&of&control&&&&public&String&execute()&{&&&&&&&&request.put("r1",&"r1");&&&&&&&&session.put("s1",&"s1");&&&&&&&&application.put("a1",&"a1");&&&&&&&&return&SUCCESS;&&&&&}&&&&@Override&&&&public&void&setRequest(Map&String,&Object&&request)&{&&&&&&&&this.request&=&&&&&}&&&&@Override&&&&public&void&setSession(Map&String,&Object&&session)&{&&&&&&&&this.session&=&&&&&}&&&&@Override&&&&public&void&setApplication(Map&String,&Object&&application)&{&&&&&&&&this.application&=&&&&&}&&&&&&&&}//第三种很少用public&class&LoginAction3&extends&ActionSupport&{&&&&&&&&private&HttpServletRequest&&&&&private&HttpSession&&&&&private&ServletContext&&&&&&&&&public&LoginAction3()&{&&&&&&&&request&=&ServletActionContext.getRequest();&&&&&&&&session&=&request.getSession();&&&&&&&&application&=&session.getServletContext();&&&&}&&&&&&&&public&String&execute()&{&&&&&&&&request.setAttribute("r1",&"r1");&&&&&&&&session.setAttribute("s1",&"s1");&&&&&&&&application.setAttribute("a1",&"a1");&&&&&&&&return&SUCCESS;&&&&&}&&&&}//第四种很少用public&class&LoginAction4&extends&ActionSupport&implements&ServletRequestAware&{&&&&&&&&private&HttpServletRequest&&&&&private&HttpSession&&&&&private&ServletContext&&&&&&&&&&&&&&&&&public&String&execute()&{&&&&&&&&request.setAttribute("r1",&"r1");&&&&&&&&session.setAttribute("s1",&"s1");&&&&&&&&application.setAttribute("a1",&"a1");&&&&&&&&return&SUCCESS;&&&&&}&&&&@Override&&&&public&void&setServletRequest(HttpServletRequest&request)&{&&&&&&&&this.request&=&&&&&&&&&this.session&=&request.getSession();&&&&&&&&this.application&=&session.getServletContext();&&&&}&&&&}jsp页面获取request/session/application中的值1&&s:property&value="#request.r1"/&&|&&%=request.getAttribute("r1")&%&&&br&/&2&&&&&&s:property&value="#session.s1"/&&|&&%=session.getAttribute("s1")&%&&&br&/&3&&&&&&s:property&value="#application.a1"/&&|&&%=application.getAttribute("a1")&%&&&br&/&4&&&&&&s:property&value="#attr.a1"/&&br&/&5&&&&&&s:property&value="#attr.s1"/&&br&/&6&&&&&&s:property&value="#attr.r1"/&&br&/&一下是我看到的一篇讲的比较详细的文章:在Struts1.*中,要想访问request、response以及session等Servlet对象是很方便的,因为它们一直是作为形参在各个方法之间进行传递的,而在Struts2中我们就很难看到它们的芳踪了,因为我们获得表单中的值都是通过预先设置好了的get方法来得到的,那么如果有些参数我们必须通过request.getParametre或者session.getAttribute来得到,那么应该怎么做呢?按照Max的教程上的说法,可以分为两种:IoC方式和非IoC方式,如何理解这两种方式的区别呢?IoC是Spring里面的特征之一,字面意思是反转控制,说白了就是依赖注入,比方说类A依赖类B,那么就主动的给A注入一个类B的对象,下面看一下这两种方法的具体实现。
1.非Ioc方式
这种方式主要是利用了com.opensymphony.xwork2.ActionContext类以及org.apache.struts2.ServletActionContext类,具体的方法如下所示。
获得request对象:
获得session对象:
在Struts2中底层的session都被封装成了Map类型,我们称之为SessionMap,而平常我们所说的session则是指HttpSession对象,具体的获得方法如下所示。
得到这个SessionMap之后我们就可以对session进行读写了,如果我们想得到原始的HttpSession可以首先得到HttpServletRequest对象,然后通过request.getSession()来取得原始的HttpSession对象。一般情况下SessionMap已经可以完成所有的工作,我们不必再去碰底层的session了。
2.IoC方式
这种方式相对来说变化就比较少了,具体流程如下所示。
获得request对象:
第一步:让action实现ServletRequestAware接口
第二步:在action中声明一个HttpServletRequest类型的实例变量
第三步:在action中实现ServletRequestAware接口的setServletRequest方法,实现方式很简单,如下所示。
private HttpServletR
public void setServletRequest(HttpServletRequest request) {
this.request =
获得Session对象(注意,此时的session是SessionMap类型):
第一步:让action实现SessionAware接口
第二步:在action中声明一个HttpServletRequest类型的实例变量
第三步:在action中实现SessionAware接口的setSession方法,实现方式很简单,如下所示。
publicvoid setSession(Map session) {
this. session =
以下是另一篇关于得到Request和Session的文章:
3031124671013141516202122232425262728293012345678910
随笔分类(94)
随笔档案(93)
文章分类(5)
文章档案(5)
很多视频对学习很有帮助
常用工具下载
积分与排名
阅读排行榜

我要回帖

更多关于 珀淳婴儿配方奶粉 的文章

 

随机推荐