我正在创建一个简单的登录页面,我想将登录和密码参数作为UTF-8编码的字符串传递.正如你在下面的代码中看到的那样,第一行是我将编码设置为UTF-8的地方,但它似乎毫无意义,因为它不起作用.当我使用带重音的登录名和密码参数时,结果页面会收到奇怪的字符.
如何以适用于所有浏览器的方式正确设置字符编码?
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My Page</title>
</head>
<body>
<h1>Welcome to My Page</h1>
<form name="login" action="login.jsp" method="POST">
Login:<br/>
<input type="text" name="login" value="" /><br/>
Password:<br/>
<input type="password" name="password" value="" /><br/>
<br/>
<input type="submit" value="Login" /><br/>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 以下代码段发出编译时错误.
char c = 'c';
char d = c + 5;
Run Code Online (Sandbox Code Playgroud)
第二行的错误说,
possible loss of precision
required: char
found: int
Run Code Online (Sandbox Code Playgroud)
该错误消息基于NetBeans IDE.
当此字符c声明final如下时.
final char c = 'c';
char d = c + 5;
Run Code Online (Sandbox Code Playgroud)
编译器时间错误消失了.
它与最终字符串的情况无关
什么是final修改有所作为吗?
我可以用什么来取代它new Date(2009, 12, 9)?
谢谢你的帮助.
我正在填充<p:selectOneMenu/>数据库,如下所示.
<p:selectOneMenu id="cmbCountry"
value="#{bean.country}"
required="true"
converter="#{countryConverter}">
<f:selectItem itemLabel="Select" itemValue="#{null}"/>
<f:selectItems var="country"
value="#{bean.countries}"
itemLabel="#{country.countryName}"
itemValue="#{country}"/>
<p:ajax update="anotherMenu" listener=/>
</p:selectOneMenu>
<p:message for="cmbCountry"/>
Run Code Online (Sandbox Code Playgroud)
加载此页面时,默认选择的选项是,
<f:selectItem itemLabel="Select" itemValue="#{null}"/>
Run Code Online (Sandbox Code Playgroud)
转换器:
@ManagedBean
@ApplicationScoped
public final class CountryConverter implements Converter {
@EJB
private final Service service = null;
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
try {
//Returns the item label of <f:selectItem>
System.out.println("value = " + value);
if (!StringUtils.isNotBlank(value)) {
return null;
} // Makes no difference, if removed.
long parsedValue …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Faces 2.2.我收到一个错误.
SEVERE: Critical error during deployment:
com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: com.sun.faces.config.ConfigurationException: Unable to parse document 'jndi:/server/contracts/WEB-INF/faces-config.xml': Unknown Schema version: 2.2
at com.sun.faces.config.ConfigManager.getConfigDocuments(ConfigManager.java:749)
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:348)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:214)
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750)
at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366)
at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2019)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
at …Run Code Online (Sandbox Code Playgroud) 如何在poi的帮助下在单元格中写出我的全部价值?
即如果值是1000.000,那么如何在不"#"之后截断000的情况下写出这个完整的值.与POI?意味着我想要全部价值.
在我的情况下,它只需要1000,但这对我来说不是正确的格式.
是否可以执行两种方法<h:commandButton>?
例如,
<h:commandButton action="#{bean.methodOne();bean.methodTwo();}" />
Run Code Online (Sandbox Code Playgroud) 以下代码段中的代码工作得很好.它计算使用类型的静态字段创建的对象的数量int是cnt.
public class Main
{
private static int cnt;
public Main()
{
++cnt;
}
public static void main(String[] args)
{
for (int a=0;a<10;a++)
{
Main main=new Main();
}
/*for (int a=0;a<10;a++)
Main main=new Main();*/
System.out.println("Number of objects created : "+cnt+"\n\n");
}
}
Run Code Online (Sandbox Code Playgroud)
它显示以下输出.
Number of objects created : 10
Run Code Online (Sandbox Code Playgroud)
唯一的问题是,当我从上面的for循环中删除这对花括号时(参见注释for循环),会发出编译时错误
不是声明.
为什么在这种特殊情况下,即使循环只包含一个语句,也必须使用一对括号?
我试图使用RequestMethod.PUT和RequestMethod.DELETESpring MVC中控制器(3.0.2版).在Spring控制器类中有三个映射方法的方法如下(分别为PUT,GET和POST,仅用于演示目的).
@RequestMapping(method = {RequestMethod.PUT}, value = {"admin_side/Temp"}, headers = {"content-type=multipart/form-data"})
public String update(@ModelAttribute("tempBean") TempBean tempBean, BindingResult error, Map model, HttpServletRequest request, HttpServletResponse response) {
if (ServletFileUpload.isMultipartContent(request)) {
System.out.println("true");
}
System.out.println("Request method PUT");
return "admin_side/Temp";
}
@RequestMapping(method = {RequestMethod.GET}, value = {"admin_side/Temp"})
public String showForm(@ModelAttribute("tempBean") TempBean tempBean, BindingResult error, Map model, HttpServletRequest request, HttpServletResponse response) {
System.out.println("Request method GET");
return "admin_side/Temp";
}
@RequestMapping(method = {RequestMethod.POST}, value = {"admin_side/Temp"})
public String onSubmit(@ModelAttribute("tempBean") TempBean tempBean, BindingResult error, Map …Run Code Online (Sandbox Code Playgroud) public class Primitive {
void m(Number b, Number ... a) {} // widening, autoboxing->widening->varargs
void m(byte b, Number ... a) {} // unboxing, autoboxing->widening->varargs
public static void main(String[] args) {
Byte b = 12;
Primitive obj = new Primitive();
obj.m(b, 23);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经搜索过并发现扩展优先级高于取消装箱,因此在上面的方法调用中,应该调用第一个方法,因为第二个参数对于两者都是相同的.但这不会发生.你可以解释一下吗?
java ×5
jsf ×3
jsf-2.2 ×2
apache-poi ×1
char ×1
converter ×1
date ×1
deprecated ×1
excel ×1
final ×1
http-delete ×1
http-post ×1
http-put ×1
jdk1.6 ×1
jsf-2 ×1
jsp ×1
loops ×1
overloading ×1
primefaces ×1
primitive ×1
servlets ×1
spring ×1
spring-mvc ×1
utf-8 ×1
wrapper ×1