| Autor |
Mensagem |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 19/10/2007 15:01:25
|
ArcanjoZer0PJ
What is classpath?
![[Avatar]](/images/avatar/0)
Membro desde: 19/10/2007 00:00:00
Mensagens: 6
Offline
|
Gostaria de Fazer o a tag pegar um campo do form digitado pelo usuario e duplica-lo.
erro:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "pass"
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:36
root cause
java.lang.NumberFormatException: For input string: "pass"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:4
java.lang.Integer.parseInt(Integer.java:447)
java.lang.Integer.parseInt(Integer.java:497)
br.estacio.Duplicar.otherDoStartTagOperations(Duplicar.java:52)
br.estacio.Duplicar.doStartTag(Duplicar.java:14
org.apache.jsp.TPExe01_jsp._jspx_meth_minhatag_005fDuplicar_005f0(TPExe01_jsp.java:111)
org.apache.jsp.TPExe01_jsp._jspService(TPExe01_jsp.java:82)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:36
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
|
|
|
 |
|
|
![[Post New]](/templates/default/images/icon_minipost_new.gif) 19/10/2007 15:02:41
|
ArcanjoZer0PJ
What is classpath?
![[Avatar]](/images/avatar/0)
Membro desde: 19/10/2007 00:00:00
Mensagens: 6
Offline
|
classe dulpicar :
* Duplicar.java
*
* Created on 20 de Setembro de 2007, 19:37
*/
package br.estacio;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.swing.*;
/**
* Generated tag handler class.
* @author aluno
* @version
*/
public class Duplicar extends BodyTagSupport {
/**
* Initialization of numero property.
*/
private int numero;
private String numero2;
/** Creates new instance of tag handler */
public Duplicar() {
super();
}
////////////////////////////////////////////////////////////////
/// ///
/// User methods. ///
/// ///
/// Modify these methods to customize your tag handler. ///
/// ///
////////////////////////////////////////////////////////////////
/**
* Method called from doStartTag().
* Fill in this method to perform other operations from doStartTag().
*
*/
private void otherDoStartTagOperations() {
JspWriter out = pageContext.getOut();
try {
numero = Integer.parseInt(numero2);
out.println(numero*2);
} catch (IOException ex) {
ex.printStackTrace();
}
//
// TODO: code that performs other operations in doStartTag
// should be placed here.
// It will be called after initializing variables,
// finding the parent, setting IDREFs, etc, and
// before calling theBodyShouldBeEvaluated().
//
// For example, to print something out to the JSP, use the following:
//
// try {
// JspWriter out = pageContext.getOut();
// out.println("something");
// } catch (IOException ex) {
// // do something
// }
//
//
}
/**
* Method called from doEndTag()
* Fill in this method to perform other operations from doEndTag().
*
*/
private void otherDoEndTagOperations() {
//
// TODO: code that performs other operations in doEndTag
// should be placed here.
// It will be called after initializing variables,
// finding the parent, setting IDREFs, etc, and
// before calling shouldEvaluateRestOfPageAfterEndTag().
//
}
/**
* Fill in this method to process the body content of the tag.
* You only need to do this if the tag's BodyContent property
* is set to "JSP" or "tagdependent."
* If the tag's bodyContent is set to "empty," then this method
* will not be called.
*/
private void writeTagBodyContent(JspWriter out, BodyContent bodyContent) throws IOException {
//
// TODO: insert code to write html before writing the body content.
// e.g.:
//
// out.println("<strong>" + attribute_1 + "</strong>");
// out.println(" <blockquote>");
//
// write the body content (after processing by the JSP engine) on the output Writer
//
bodyContent.writeOut(out);
//
// Or else get the body content as a string and process it, e.g.:
// String bodyStr = bodyContent.getString();
// String result = yourProcessingMethod(bodyStr);
// out.println(result);
//
// TODO: insert code to write html after writing the body content.
// e.g.:
//
// out.println(" </blockquote>");
// clear the body content for the next time through.
bodyContent.clearBody();
}
////////////////////////////////////////////////////////////////
/// ///
/// Tag Handler interface methods. ///
/// ///
/// Do not modify these methods; instead, modify the ///
/// methods that they call. ///
/// ///
////////////////////////////////////////////////////////////////
/**
* This method is called when the JSP engine encounters the start tag,
* after the attributes are processed.
* Scripting variables (if any) have their values set here.
* @return EVAL_BODY_BUFFERED if the JSP engine should evaluate the tag body, otherwise return SKIP_BODY.
* This method is automatically generated. Do not modify this method.
* Instead, modify the methods that this method calls.
*/
public int doStartTag() throws JspException, JspException {
otherDoStartTagOperations();
if (theBodyShouldBeEvaluated()) {
return EVAL_BODY_BUFFERED;
} else {
return SKIP_BODY;
}
}
/**
* This method is called after the JSP engine finished processing the tag.
* @return EVAL_PAGE if the JSP engine should continue evaluating the JSP page, otherwise return SKIP_PAGE.
* This method is automatically generated. Do not modify this method.
* Instead, modify the methods that this method calls.
*/
public int doEndTag() throws JspException, JspException {
otherDoEndTagOperations();
if (shouldEvaluateRestOfPageAfterEndTag()) {
return EVAL_PAGE;
} else {
return SKIP_PAGE;
}
}
/**
* This method is called after the JSP engine processes the body content of the tag.
* @return EVAL_BODY_AGAIN if the JSP engine should evaluate the tag body again, otherwise return SKIP_BODY.
* This method is automatically generated. Do not modify this method.
* Instead, modify the methods that this method calls.
*/
public int doAfterBody() throws JspException {
try {
//
// This code is generated for tags whose bodyContent is "JSP"
//
BodyContent bodyContent = getBodyContent();
JspWriter out = bodyContent.getEnclosingWriter();
writeTagBodyContent(out, bodyContent);
} catch (Exception ex) {
handleBodyContentException(ex);
}
if (theBodyShouldBeEvaluatedAgain()) {
return EVAL_BODY_AGAIN;
} else {
return SKIP_BODY;
}
}
/**
* Handles exception from processing the body content.
*/
private void handleBodyContentException(Exception ex) throws JspException {
// Since the doAfterBody method is guarded, place exception handing code here.
throw new JspException("error in NewTag: " + ex);
}
/**
* Fill in this method to determine if the rest of the JSP page
* should be generated after this tag is finished.
* Called from doEndTag().
*/
private boolean shouldEvaluateRestOfPageAfterEndTag() {
//
// TODO: code that determines whether the rest of the page
// should be evaluated after the tag is processed
// should be placed here.
// Called from the doEndTag() method.
//
return true;
}
/**
* Fill in this method to determine if the tag body should be evaluated
* again after evaluating the body.
* Use this method to create an iterating tag.
* Called from doAfterBody().
*/
private boolean theBodyShouldBeEvaluatedAgain() {
//
// TODO: code that determines whether the tag body should be
// evaluated again after processing the tag
// should be placed here.
// You can use this method to create iterating tags.
// Called from the doAfterBody() method.
//
return false;
}
/**
* Fill in this method to determine if the tag body should be evaluated.
* Called from doStartTag().
*/
private boolean theBodyShouldBeEvaluated() {
//
// TODO: code that determines whether the body should be
// evaluated should be placed here.
// Called from the doStartTag() method.
//
return true;
}
/**
* Setter for the numero attribute.
*/
public void setNumero(int value) {
this.numero = value;
}
public void setNumero2(String numero2) {
this.numero2 = numero2;
}
}
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 19/10/2007 15:03:27
|
ArcanjoZer0PJ
What is classpath?
![[Avatar]](/images/avatar/0)
Membro desde: 19/10/2007 00:00:00
Mensagens: 6
Offline
|
index jsp :
<%@taglib uri="/WEB-INF/tlds/duplicar" prefix="minhatag" %>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>JSP Page</h1>
<form action="TPExe01.jsp" method="POST">
<input type="submit" value="envia" />
<input type="password" name="pass" value="" />
</form>
</body>
</html>
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 19/10/2007 15:06:56
|
ArcanjoZer0PJ
What is classpath?
![[Avatar]](/images/avatar/0)
Membro desde: 19/10/2007 00:00:00
Mensagens: 6
Offline
|
classe TPExe01
<%@taglib uri="/WEB-INF/tlds/duplicar" prefix="minhatag" %>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<minhatag uplicar numero2="pass" />
</body>
</html>
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 19/10/2007 15:07:49
|
ArcanjoZer0PJ
What is classpath?
![[Avatar]](/images/avatar/0)
Membro desde: 19/10/2007 00:00:00
Mensagens: 6
Offline
|
tld:
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns si="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>duplicar</short-name>
<uri>/WEB-INF/tlds/duplicar</uri>
<!-- A validator verifies that the tags are used correctly at JSP
translation time. Validator entries look like this:
<validator>
<validator-class>com.mycompany.TagLibValidator</validator-class>
<init-param>
<param-name>parameter</param-name>
<param-value>value</param-value>
</init-param>
</validator>
-->
<!-- A tag library can register Servlet Context event listeners in
case it needs to react to such events. Listener entries look
like this:
<listener>
<listener-class>com.mycompany.TagLibListener</listener-class>
</listener>
-->
<tag>
<name>Duplicar</name>
<tag-class>br.estacio.Duplicar</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>numero2</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>numero</name>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
</tag>
</taglib>
xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns si="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 20/10/2007 09:27:04
|
BrunoBastosPJ
GUJ Master
![[Avatar]](/images/avatar/f2ac51f4c59265a0c022339c16119936.png)
Membro desde: 17/06/2005 00:00:00
Mensagens: 1124
Offline
|
Opa... Vou te dar uma dica... Colar a classe toda sem utilizar BBCode é meio complicado para os outros entenderem...
Dê uma olhada nestas linhas da classe Duplicar.java
br.estacio.Duplicar.otherDoStartTagOperations(Duplicar.java:52)
br.estacio.Duplicar.doStartTag(Duplicar.java:14
Você provávelmente está tentando converter a String pass para um int.
Se você der uma olhada na API
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
Vai ver que o método parseInt lança essa exceção
Espero ter ajudado.
|
A realidade é apenas uma ilusão provocada devido a ausência de álcool.
http://www.jug-petropolis.org/ |
|
|
 |
|
|